【问题标题】:How to display JSON data in Dojo DataGrid using JsonRest and ObjectStore if JSON is wrapped in a Array如果 JSON 包装在数组中,如何使用 JsonRest 和 ObjectStore 在 Dojo DataGrid 中显示 JSON 数据
【发布时间】:2013-02-17 21:45:39
【问题描述】:

我正在使用 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"
}]}

【问题讨论】:

  • 你不能简单地添加一个步骤来提交stuff.items吗?
  • 查看my answer使用 Dojo 的 dgrid、JsonRest 和子行/数组

标签: dojo dojox.grid.datagrid


【解决方案1】:

您可以像处理 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"
}]

【讨论】:

    猜你喜欢
    • 2013-09-13
    • 1970-01-01
    • 1970-01-01
    • 2012-04-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2018-04-18
    相关资源
    最近更新 更多