【发布时间】:2012-03-23 11:21:50
【问题描述】:
我有两个数据模型:Writer.AttributValeur 和 Writer.Produit。
Writer.Produit 与Writer.AttributValeur 有一对一关系。
我想显示(并创建/编辑/删除)Writer.Produit 的列表。我希望能够将Writer.AttributValeur 添加到当前的Writer.Produit。
这就是我所做的:两家商店:
- 第一个与网格(和表单)链接以显示(并创建/编辑/删除)
Writer.Produit的列表。 - 第二个用于显示
Writer.AttributValeur的列表(仅列表)
在第一个网格中,有一个按钮“添加AttributValeur”。当用户单击它时,我会显示一个 Windows,其中有一个与第二个商店链接的网格。如果用户选择了一条记录,然后单击 sur ok,我可以使用此代码获取 Writer.AttributValeur 记录:
var currentAttribut = gridAttributs.getView()
.getSelectionModel()
.getSelection()[0];
我想将这条记录 currentAttribut 添加到 Writer.Produit 存储中。
知道怎么做吗?以下是我的数据模型的 ExtJS 声明,以及我的商店的创建。
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'
}
}
});
var storeAttributs = Ext.create('Ext.data.Store', {
model: 'Writer.AttributValeur',
autoLoad: true,
autoSync: true,
proxy: {
type: 'ajax',
api: {
read: 'json/attributs/'
},
reader: {
type: 'json',
successProperty: 'success',
root: 'data',
messageProperty: 'message'
}
}
});
【问题讨论】: