将 JSON 数据加载到 ExtJS 数据存储中时遇到问题
关于如何配置 ExtJS 数据存储来读取传入的 JSON 数据,我已经尝试了所有我能想到的组合。我正在获取此 JSON 数据:
[{ "data_type": {"attribute1" : "value1",
"attribute2" : "value2",
"attribute3" : "value3"
}
},
{ "data_type": {"attribute1": "value4",
"attribute2" : "value5",
"attribute3" : "value6"
}
}
]
我不想解析 JSON 并重新格式化它以使 ExtJS 满意,因为它看起来多余。我想要最终得到的是一个数据存储,它允许我执行以下操作:
Ext.create('Ext.container.Container',
{
id: 'junk',
renderTo: 'slider',
width: 960,
height:600,
layout: 'vbox',
items: [
{
xtype: 'grid',
title: 'foobar',
height: 400,
width: 700,
store: my_store,
viewConfig: { emptyText: 'No data' },
columns: [
{
text: 'column1',
dataIndex: 'attribute1'
},{
text: 'column2',
dataIndex: 'attribute2'
},{
text: 'column3',
dataIndex: 'attribute3'
}
]
}
]
}
我知道 ExtJS 知道如何解析此 JSON,因为我可以执行以下操作:
var foo = Ext.decode(data);
var good_data = foo[0].data_type.attribute1
并且如我所期望的那样返回“value1”。谁能帮助我理解获取数据模型和存储来做到这一点的神奇咒语?
谢谢!
I've tried every combination I can think of in terms of how to configure my ExtJS datastore to read my incoming JSON data. I'm getting this JSON data in:
[{ "data_type": {"attribute1" : "value1",
"attribute2" : "value2",
"attribute3" : "value3"
}
},
{ "data_type": {"attribute1": "value4",
"attribute2" : "value5",
"attribute3" : "value6"
}
}
]
I don't want to parse the JSON and reformat it in order to make ExtJS happy because it seems redundant. What I want to end up with is a datastore which would allow me to do:
Ext.create('Ext.container.Container',
{
id: 'junk',
renderTo: 'slider',
width: 960,
height:600,
layout: 'vbox',
items: [
{
xtype: 'grid',
title: 'foobar',
height: 400,
width: 700,
store: my_store,
viewConfig: { emptyText: 'No data' },
columns: [
{
text: 'column1',
dataIndex: 'attribute1'
},{
text: 'column2',
dataIndex: 'attribute2'
},{
text: 'column3',
dataIndex: 'attribute3'
}
]
}
]
}
I know ExtJS knows how to parse this JSON, because I can do:
var foo = Ext.decode(data);
var good_data = foo[0].data_type.attribute1
And that returns 'value1' as I would expect. Can anyone help me understand the magical incantation to get a datamodel and store to do that?
Thanks!
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
首先,您应该创建模型:
然后您可以通过将
record
属性设置为data_type
来配置存储以支持您的数据格式:工作示例:http://jsfiddle.net/lolo/WfXK6/1/
First of all you should create model:
Then you can configure store to support your data format by setting
record
property todata_type
:Working sample: http://jsfiddle.net/lolo/WfXK6/1/