【发布时间】:2011-12-28 21:54:42
【问题描述】:
我尝试使用来自与包含 ExtJs 代码的 Javascript 文件位于同一域中的 JSON 文件中的数据来实现网格面板。我正在使用 ExtJs 3.4。
网格显示,但其中没有任何数据。 Firebug 显示一条错误消息,告诉我 JSON 文件的第一行有错误(“格式不正确”)。我已经验证了 JSON 文件,一切正常。
这是我的代码:
Ext.onReady(function () {
var myStore = new Ext.data.JsonStore({
url: 'data.json',
root: 'rows',
autoLoad: true,
fields: [{
name: 'person',
type: 'string'
}, {
name: 'product',
type: 'string'
}]
});
var grid = new Ext.grid.GridPanel({
id: 'gridPanel',
title: 'Grid example',
width: 250,
height: 250,
renderTo: 'grid-example',
store: myStore,
columns: [{
header: 'Person',
dataIndex: 'person'
}, {
header: 'Product',
dataIndex: 'product'
}]
});
});
我的 JSON 数据是:
{
"rows": [{
"person": "Jamie Avins",
"product": "Ladder"
}, {
"person": "Ed Spencer",
"product": "Spanner"
}]
}
你有什么想法吗?有人可以给我一些提示吗?
提前致谢!
塞哈
【问题讨论】:
-
对 data.json 的调用是否已被触发?签入控制台
-
嗨,bensiu,感谢您的提示。我将 autoLoad 设置为 true 并尝试了 myStore.load()。数据已加载,但 firebug 显示格式不正确。
标签: json extjs gridpanel http-proxy jsonstore