【发布时间】:2012-11-23 15:04:30
【问题描述】:
我有两个数据模型:Writer.AttributValeur 和 Writer.Produit。
Writer.Produit 与 Writer.AttributValeur 有 HasMany / BelongsTo 关系。
所以定义是这样的:
Ext.define('Writer.AttributValeur', {
extend: 'Ext.data.Model',
fields: [{
name: 'id',
type: 'int',
useNull: true
},
'description',
'val'
],
belongsTo: 'Writer.Produit'
});
Ext.define('Writer.Produit', {
extend: 'Ext.data.Model',
fields: [{
name: 'id',
type: 'int',
useNull: true
},
'titre',
'description'
],
hasMany: {
model: 'Writer.AttributValeur',
name: 'attributs'
}
});
var store = Ext.create('Ext.data.Store', {
model: 'Writer.Produit',
autoLoad: true,
autoSync: true,
proxy: {
type: 'ajax',
api: {
read: 'json/liste_view/',
create: 'json/item/?mode=create',
update: 'json/item/?mode=update',
destroy: 'json/item/?mode=destroy'
},
reader: {
type: 'json',
successProperty: 'success',
root: 'data',
messageProperty: 'message'
},
writer: {
type: 'json',
writeAllFields: true,
root: 'data'
}
}
});
现在,当我阅读文件并询问“产品”时,有一个完美运行的 AJAX 答案:
并且在每一“行”中,有很多Writer.AttributValeur(我将它们别名为“属性”见图):
问题是当我在此“attributs”字段中插入Writer.AttributValeur 时,如下所示:
form.getRecord().attributs().add(newrecord);
它工作得很好,但是当我打电话给store.sync() 时没有任何反应。所以我手动将记录标记为dirty:
form.getRecord().attributs().add(newrecord);
form.getRecord().setDirty();
form.getRecord().store.sync();
现在已发送,但attributs 未发送!见:
我应该如何将它“添加”到更新过程中?
【问题讨论】: