我正在尝试使用Ext JS 4并且正在使用其中一个网格示例,并且希望使用JSON而不是XML。无论我如何编写JSON数据,我都没有加载记录。
这是我的代码:
Ext.define('Plant', {
extend: 'Ext.data.Model',
fields: [{
name: 'common',
type: 'string'
}, {
name: 'botanical',
type: 'string'
}, {
name: 'light'
}, ]
});
// Create the Data Store.
var store = Ext.create('Ext.data.Store', {
// Destroy the store if the grid is destroyed.
autoDestroy: true,
model: 'Plant',
proxy: {
type: 'ajax',
url: 'plants.json',
reader: {
type: 'json',
root: 'records'
}
},
sorters: [{
property: 'common',
direction: 'ASC'
}]
});
这是我的数据:
{
"records": [
{
"common": "Bloodroot",
"botanical": "Sanguinaria canadensis",
"light": "Mostly Shady"
}, {
"common": "test",
"botanical": "I do not know",
"light": "Mostly Shady"
}
]
}
XML阅读器效果很好,但我们想要使用JSON。
提前致谢
答案 0 :(得分:1)
看看这个thread!您需要检查 plants.json 的 网址 路径,路径从'index.html'或其他类似的起点开始,而不是商店所在的.js文件。我测试了你的代码并且工作正常,在你的Ext.data.Store中也使用 autoLoad:true ,我没看到你的网格代码所以..干杯!