我编写了一个简单的程序来从外部 JSON
文件获取数据并将其显示在 Dojo Gridx
中。但是,它不起作用。
Dojo 代码:
require(["dojo/text!json_to_gridx/js/data.json", "dojo/json", "gridx/Grid"], function(myJSONData, JSON, Gridx) {
// fetch and parse JSON
var myJSON = JSON.parse(myJSONData);
console.log(myJSON); // working fine
// create datastore
var store = myJSON; // should this be changed?
// create Gridx
if(!window.grid){
console.log('working'); // working fine
gridx = new Gridx({
id: 'grid',
store: store,
structure: [
{id: 'name', field: 'name', name: 'Name'},
{id: 'company', field: 'company', name: 'Company'}
]
});
console.log('working2'); // does not work
gridx.placeAt('gridContainer');
gridx.startup();
}
});
JSON:
[{"name": "Rahul Desai","company": "PSL"},{"name": "Alston","company": "PSL"}]
我收到错误:
TypeError: cacheClass is not a constructor Model.js
我该如何解决这个问题?请帮忙!
编辑:建议我使用内存存储
和“gridx/core/model/cache/Async”
现在,创建 Gridx 的代码如下所示:
this._disksGrid = new Gridx({
id: 'grid',
cacheClass: asyncCache,
store: store,
structure: [
{id: 'name', field: 'name', name: 'Name'},
{id: 'company', field: 'company', name: 'Company'}
]
});
现在没有错误,但 Gridx 未显示。知道为什么吗?
编辑2:原来我在之前的编辑中启动了错误的网格。现在 Gridx 显示,但第二个值重复,并且第一个值现在显示。
Name Company
Alston PSL
Alston PSL
最佳答案
我进行了编辑和编辑 2 中提到的更改,并向每一行 JSON 添加了唯一 ID 并正确验证了它。这样问题就解决了。
关于javascript - 无法从 JSON 数据显示 Gridx,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/21472394/