【发布时间】:2012-05-31 15:19:05
【问题描述】:
所以我有一个父子商店,如下所示:
父模型
Ext.define('APP.model.Client', {
extend: 'Ext.data.Model',
requires: [
'APP.model.Website', 'Ext.data.association.HasMany', 'Ext.data.association.BelongsTo'],
fields: [{
name: 'id',
type: 'string'
}, {
name: 'name',
type: 'string'
}, {
name: 'slug',
type: 'string'
}, {
name: 'active',
type: 'boolean'
}, {
name: 'current',
type: 'boolean'
}],
hasMany: {
model: 'APP.model.Website',
name: 'websites'
}
});
儿童模型
Ext.define('APP.model.Website', {
extend: 'Ext.data.Model',
fields: [{
name: 'id',
type: 'string'
}, {
name: 'client_id',
type: 'string'
}, {
name: 'sub_domain',
type: 'string'
}, {
name: 'active',
type: 'boolean'
}],
belongsTo: 'APP.model.Client'
});
通过服务器使用 AJAX 调用,我正在加载 Clients 存储,并且加载正常。但是 Websites 存储没有填充,当我在 Clients 存储 on.load 函数上断点时,查看它填充了什么,Client 存储仅填充了客户端数据,但在 @该商店的 987654328@ 属性,我可以看到所有 websites 数据。所以它被正确返回,但我的 extjs 不正确。这里是商店:
客户端商店
Ext.define('APP.store.Clients', {
extend: 'Ext.data.Store',
autoLoad: false,
model: 'APP.model.Client',
proxy: {
type: 'ajax',
url: '/client/list',
reader: {
type: 'json',
root: 'items'
}
},
sorters: [{
property: 'name',
direction: 'ASC'
}]
});
网站商店
Ext.define('APP.store.Websites', {
extend: 'Ext.data.Store',
requires: ['Ext.ux.Msg'],
autoLoad: false,
model: 'APP.model.Website',
proxy: {
type: 'ajax',
url: '/client/list',
reader: {
type: 'json',
root: 'items'
},
writer: {
type: 'json'
}
},
sorters: [{
property: 'sub_domain',
direction: 'ASC'
}]
});
我的最终结果是...我想填充两个商店,以便我可以单击一个元素,当它从父商店加载某些内容时,我可以访问子商店(当我发现了这个问题)在选项卡中填充几个网格。
就我的设置而言,我缺少什么?几天前我刚刚下载了extjs4,所以我在4.1上。
【问题讨论】:
-
当您使用关联时,extjs 并未使用您的网站商店。相反,它创建了自己的普通商店。有关更多信息,请查看我的回答 here。
-
以你的例子,看来我需要做
selectedClient.websites().load(),但我面临同样的问题。相关数据未正确加载到存储/模型中(请注意我对下面答案的评论),因此我收到错误Object has no method 'websites'。从服务器返回数据时,它没有正确加载到模型/存储中,因此其中一个存在配置问题。 -
然后当我将
hasMany: {model: 'Website', name: 'websites'}更改为hasMany: {model: 'APP.model.Website', name: 'websites'}时,我收到一个新错误Cannot call method 'indexOf' of undefined。所以看起来它正在识别 website() 方法,但我现在有一个新错误。我将通过调试文件来尝试看看发生了什么。 -
当我运行这个
selectedClient.websites().load()时,它看起来好像找到了带有websites()的正确存储,但是代理中没有配置 URL。正如您在我上面的定义中看到的那样,我确实在代理上配置了一个 URL...