2014-01-31 41 views
1

我写了一个简单的程序来从外部JSON文件中获取数据并将其显示在Dojo Gridx中。但是,它不起作用。无法显示来自JSON数据的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 

我如何解决这个问题?请帮忙!

编辑:我被建议使用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 
+0

干得好!我忘了在我的网格中添加cacheClass:asyncCache。你让我今天一整天都感觉很好!!谢谢... – saravanakumar

+0

@saravanakumar我很高兴它帮助。 –

回答

0

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

相关问题