4
我在創建多對多關聯時遇到了一些問題。因爲它不知道。我嘗試以這種方式建立關係。但我不確定。任何人都可以幫助我?我該怎麼做?。這裏是我的代碼Extjs 4.1多對多模型關聯
Ext.define('Ext4Example.model.Category', {
extend : 'Ext.data.Model',
alias : 'widget.categoryModel',
idProperty: 'id',
fields: [
{name:'id', mapping:'id', type:'int'},
{name:'name', mapping:'name', type:'string'}
],
proxy: {
type: 'ajax',
noCache: false,
api: {
create : '${createLink(controller:'category', action: 'create')}',
read : '${createLink(controller:'category', action: 'read')}',
update : '${createLink(controller:'category', action: 'update')}',
destroy : '${createLink(controller:'category', action: 'destroy')}'
},
actionMethods: {
create : 'POST',
read : 'GET',
update : 'PUT',
destroy : 'DELETE'
},
reader: {
type : 'json',
root : 'data',
totalProperty : 'total',
successProperty : 'success',
messageProperty : 'message',
implicitIncludes: true
},
writer: {
type : 'json',
root : 'data',
writeAllFields: true
},
simpleSortMode: true
},
hasMany: [{model: 'Manufacturer', name: 'manufacturers'}]
});
第二模型是這裏
Ext.define('Ext4Example.model.Manufacturer', {
extend : 'Ext.data.Model',
alias : 'widget.manufacturerModel',
idProperty: 'id',
fields: [
{name:'id', mapping:'id', type:'int'},
{name:'name', mapping:'name', type:'string'}
],
proxy: {
type: 'ajax',
noCache: false,
api: {
create : '${createLink(controller:'manufacturer', action: 'create')}',
read : '${createLink(controller:'manufacturer', action: 'read')}',
update : '${createLink(controller:'manufacturer', action: 'update')}',
destroy : '${createLink(controller:'manufacturer', action: 'destroy')}'
},
actionMethods: {
create : 'POST',
read : 'GET',
update : 'PUT',
destroy : 'DELETE'
},
reader: {
type : 'json',
root : 'data',
totalProperty : 'total',
successProperty : 'success',
messageProperty : 'message',
implicitIncludes: true
},
writer: {
type : 'json',
root : 'data',
writeAllFields: true
},
simpleSortMode: true
},
hasMany: [{model: 'Category', name: 'categories'}]
});