如果JSON包装在Array中,如何使用JsonRest和ObjectStore在Dojo DataGrid中显示JSON数据

时间:2013-02-17 21:45:39

标签: dojo dojox.grid.datagrid

我使用Dojo 1.6渲染一个简单的DatGrid。我遇到的唯一问题与dojo 1.6 DataGrid cannot display lists?相似 这里的解决方案以及此处http://dojotoolkit.org/documentation/tutorials/1.6/store_driven_grid/的引用确实起作用,但JSON结构仍存在一个问题。以下是工作和非工作示例。我在格式中获取JSON,其中所有内容都包含在items数组中。我如何使它工作?

正在运行的json格式

[{
    "bolist": ["CHM", "CVO", "PMO"],
    "title": "How do I do",
    "painpoints": ["this", "that", "manay more"],
    "solution": "wondeful"
}, {
    "bolist": ["DGM", "EXE", "CLI"],
    "title": "There we go",
    "painpoints": ["Front", "back", "many other places"],
    "solution": "under review"
}]

无效的json格式(我以这种格式获取json)

{"items":[{
    "bolist": ["CHM", "CVO", "PMO"],
    "title": "How do I do",
    "painpoints": ["this", "that", "manay more"],
    "solution": "wondeful"
}, {
    "bolist": ["DGM", "EXE", "CLI"],
    "title": "There we go",
    "painpoints": ["Front", "back", "many other places"],
    "solution": "under review"
}]}

1 个答案:

答案 0 :(得分:0)

你可以像javascript对象一样处理json!所以尝试将jsonReturn.items提供给网格。这样网格只获得你想要的json数据:

[{
    "bolist": ["CHM", "CVO", "PMO"],
    "title": "How do I do",
    "painpoints": ["this", "that", "manay more"],
    "solution": "wondeful"
}, {
    "bolist": ["DGM", "EXE", "CLI"],
    "title": "There we go",
    "painpoints": ["Front", "back", "many other places"],
    "solution": "under review"
}]