ExtJS 4 问题,尝试对深层嵌套的 JSON 数据进行更新
我的 Json 数据:-
{
"attributes": {
"list": [
{
"name":"attribute2",
"value":"attribute2 value"
}, {
"name":"attribute1",
"value":"attribute1 value"
}]
}
"name":"name1",
"id":1234
}
我的商店定义:-
Ext.define('Attr', {
extend: 'Ext.data.Store',
model: 'Attribute',
autoLoad: true,
proxy: {
type: 'rest',
url: 'data/1234',
api: {
update: 'newdata/1234'
},
reader: {
type: 'json',
root: 'attributes.list'
}
}
});
我的模型定义:-
Ext.define('Attribute', {
extend: 'Ext.data.Model',
fields: ['name','value']
});
显示上述商店的视图:-
{
xtype: 'grid',
store: 'Attr',
id: 'attrpanel',
columns: [
{
header: 'Name',
sortable: true,
dataIndex: ['name'],
flex: 1
}, {
header: 'Value',
sortable: true,
dataIndex: ['value'],
flex: 1
}]
}
当前情况:我可以显示 Json 对象中的数据值。
问题:每当我在编辑字段后在控制器中调用 this.getAttrStore().sync() 时,都会收到错误。 我搜索了许多论坛,发现更新深度嵌套的 JSON 数据时似乎存在一些问题。
我曾想过购买 Peter Muller 的补丁,但我还没有真正尝试过。
如果我错了,请纠正我,或者如果你能指出我一些有用的东西,这将是一个很大的帮助。
非常感谢!
My Json data:-
{
"attributes": {
"list": [
{
"name":"attribute2",
"value":"attribute2 value"
}, {
"name":"attribute1",
"value":"attribute1 value"
}]
}
"name":"name1",
"id":1234
}
My Store Definition:-
Ext.define('Attr', {
extend: 'Ext.data.Store',
model: 'Attribute',
autoLoad: true,
proxy: {
type: 'rest',
url: 'data/1234',
api: {
update: 'newdata/1234'
},
reader: {
type: 'json',
root: 'attributes.list'
}
}
});
My Model Definition:-
Ext.define('Attribute', {
extend: 'Ext.data.Model',
fields: ['name','value']
});
The view for displaying the above store:-
{
xtype: 'grid',
store: 'Attr',
id: 'attrpanel',
columns: [
{
header: 'Name',
sortable: true,
dataIndex: ['name'],
flex: 1
}, {
header: 'Value',
sortable: true,
dataIndex: ['value'],
flex: 1
}]
}
Current Situation: I can display the data values from the Json object.
Problem: Whenever I call this.getAttrStore().sync() in my controller after editing the fields, I get an error.
I have searched through number of forums and realized that there seems to some problem while updating deeply nested JSON data.
I have thought of getting Peter Muller's patch but I havent really given that a shot.
Please correct me if I am wrong or if you could point me towards something useful, it would be a big help.
Many Thanks!
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
据我所知,Ext JS 4.0 可能支持读取嵌套 JSON,但它似乎不支持提交相同的 JSON。我遇到了 Order 包含 OrderItems 的问题。 Ext 可以很好地读取它,但调用 Order.Save 不会包含这些项目。
这篇文章并不是决定性的,因为 sencha 团队还没有回复它,但用户似乎说它不受支持。
http://www.sencha .com/forum/showthread.php?144653-ExtJS-4-updating-deeply-nested-Json-Data
From what I gather Ext JS 4.0 might support reading nested JSON but it doesn't seem to support submitting that same JSON. I have this issue where Order contains OrderItems. Ext can read it fine but calling Order.Save won't include the items.
This post is by no way conclusive because the sencha team haven't replied to it but a user seems to say that it just isn't supported.
http://www.sencha.com/forum/showthread.php?144653-ExtJS-4-updating-deeply-nested-Json-Data
我遇到了同样的问题,并最终使用了 Beachdog 的 Sencha 论坛。
他使用覆盖将关联的数据应用到记录,然后保存它:
然后您可以使用覆盖作为模型中的要求,如下所示:
恕我直言,这是一个优雅而直接的解决方案;所有的功劳都归海滩狗所有。
I had the same issue, and ended using a solution from the Sencha forums by beachdog.
He uses an override to apply the associated data to the record before saving it:
Then you can use the override as a requirement in your models, like the following:
IMHO, an elegant and straight-forward solution; all credits go to beachdog.
你得到什么错误?
您是在 HTTP 请求之前还是之后收到此错误?
服务器发送的响应是什么?
无论如何,我建议为您的代理配置一个编写器。
What error do you get?
Do you get this error before or after the HTTP request?
What is the response sent by the server?
Anyway, I suggest to configure a writer for your proxy.