无法从JSON数据显示Gridx

时间:2014-01-31 04:26:38

标签: javascript dojo

我编写了一个简单的程序来从外部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

1 个答案:

答案 0 :(得分:0)

我做了EDIT和EDIT 2中提到的更改,并且还为JSON的每一行添加了唯一ID并正确验证了它。这解决了这个问题。

相关问题