[英]Unable to display Gridx from JSON data
我编写了一个简单的程序来从外部JSON
文件中获取数据并将其显示在Dojo Gridx
。 但是,它不起作用。
道场代码:
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
我该如何解决? 请帮忙!
编辑:建议使用Memory Store
和"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
我进行了EDIT和EDIT 2中提到的更改,还向JSON的每一行添加了唯一的ID并正确地对其进行了验证。 那解决了问题。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.