ExtJS 4:编写带有模型关联的嵌套XML
ExtJS 4: Write nested XML with model associations
我正试图通过模型关联编写嵌套的XML数据,但我无法继续。
首先是XML:
<?xml version="1.0" encoding="utf-8"?>
<card>
<generalData>
<name>A card</name>
<description>That's a description</description>
</generalData>
<specificData>
<number>100</number>
<type>int</type>
</specificData>
<otherStuff>
<note>Those notes...</note>
</otherStuff>
</card>
以下是型号代码:
Ext.define ('generalData', {
extend: 'Ext.data.Model' ,
fields: ['name', 'description']
});
Ext.define ('specificData', {
extend: 'Ext.data.Model' ,
fields: ['number', 'type']
});
Ext.define ('otherStuff', {
extend: 'Ext.data.Model' ,
fields: ['note']
});
Ext.define ('Card', {
extend: 'Ext.data.Model' ,
requires: ['generalData', 'specificData', 'otherStuff'] ,
hasOne: [{
name: 'generalData' ,
model: 'generalData' ,
getterName: 'getGeneralData' ,
associationKey: 'generalData' ,
reader: {
type: 'xml' ,
root: 'generalData' ,
record: 'generalData'
} ,
writer: {
type: 'xml' ,
documentRoot: 'generalData' ,
record: 'generalData'
}
} , {
name: 'specificData' ,
model: 'specificData' ,
getterName: 'getSpecificData' ,
associationKey: 'specificData' ,
reader: {
type: 'xml' ,
root: 'specificData' ,
record: 'specificData'
} ,
writer: {
type: 'xml' ,
documentRoot: 'specificData' ,
record: 'specificData'
}
} , {
name: 'otherStuff' ,
model: 'otherStuff' ,
getterName: 'getOtherStuff' ,
associationKey: 'otherStuff' ,
reader: {
type: 'xml' ,
root: 'otherStuff' ,
record: 'otherStuff'
} ,
writer: {
type: 'xml' ,
documentRoot: 'otherStuff' ,
record: 'otherStuff'
}
}] ,
proxy: {
type: 'ajax' ,
url: '/card' ,
reader: {
type: 'xml' ,
record: 'card' ,
root: 'card'
} ,
writer: {
type: 'xml' ,
documentRoot: 'card' ,
record: 'card' ,
header: '<?xml version="1.0" encoding="utf-8"?>'
}
}
});
正如你所看到的,每个模型都有自己的读者和作者(最后一个真的需要吗?)。
在这里,我检索数据并尝试将其发送回服务器。
Card.load (1, {
success: function (card) {
console.log (card);
var gd = card.getGeneralData (function (data) {
console.log (data.get ('name'));
data.set ('name', 'Another card');
});
card.save ();
}
});
当调用"success"函数时,我得到了我请求的所有XML,并且在控制台上写下了"A card"。然后,我尝试在"另一张卡"中更改卡的名称,并使用card.save()将数据发回。在这一点上,我遇到了三种问题:
1) 请求paylod(发送到服务器的数据)不是我在上一个请求中得到的XML。事实上,它有以下结构:
<?xml version="1.0" encoding="utf-8"?>
<card>
<card>
<id></id>
</card>
</card>
我得到这个结构是因为作者:空的,有两个相等的元素和一个新元素("id"),我没有指定任何地方。因此,第一个问题是:如何将单个documentRoot或记录元素添加到要发送的数据中
2) 第二点是:我的数据在哪里?为什么发送的XML为空?我在模型保存过程中做得对吗
3) 最后,第三个问题是:请求的内容类型是text/xml。那么,如何将其更改为application/xml
模特协会可以阅读,但我真的不明白它们是如何与写作联系在一起的。我想要的只是读取XML数据,修改一些字段,然后再次将其发送回,所有内容都使用XML格式
我在Sencha论坛上问过,这就是答案:
编写器目前不支持嵌套。
斯科特。
因此,到目前为止,这是不可能的;)
相关文章:
- ExtJS 4:编写带有模型关联的嵌套XML
- Sequelize associations:set[Models]添加新模型,而不是关联现有模型
- 选择框中带有关联的ng模型,选项中带有ng重复
- 如何更改与Backbone集合中的模型相关联的几个元素的css属性
- 何时指定与主干中的集合/视图关联的模型
- Rails4:从Javascript调用的Action;t请参阅模型关联(NoMethodError)
- 与设计用户相关联的多个模型-根据角色选择填写一个模型
- 如何在创建后立即显示关联模型的特性
- 嵌套的XML数据和ExtJS模型关联
- 检查是否显示与当前视图模型关联的 DOM
- 在 sencha 触摸 2 下的关联模型中进行过滤
- 如何从续集关联模型中获取价值
- Ember.js将动作发送到'belongsTo'关联模型
- 在保存[Rrails,Ajax,GoogleMaps]之前临时创建和关联模型
- 如何在cakeHP中为关联模型保存多个字段
- 在sails.js中关联模型的Where子句
- 如何使用Sails 0.10.x在一对多关系中引用关联模型
- 以与JSON相同的方式嵌套Sencha-touch关联模型
- ExtJS 6网格按关联模型分组
- 无法从Jquery访问关联模型