问题描述
是否可以在 ExtJS 4 中更改网格的存储?
Is it posible to change grid's store in ExtJS 4?
例如,我有两个模型:
User = Ext.define('User',{
extend: 'Ext.data.Model',
[...],
hasMany: 'Product'
});
Product = Ext.define('Product',{
extend: 'Ext.data.Model',
[...]
});
和两个网格.第一个网格与使用 User
模型并从后端加载嵌套 json 数据的 Store 链接,如
and two grids.The first grid is linked with Store which uses User
model and loads nested json data from backend, like
{
users: [{
id: 1,
products: [
{id: 1},
{id: 2}
]
}, {
id: 2,
products: [
{id: 3},
{id: 4},
{id: 5}
]
}]
}
我想要得到的只是当您单击第一个网格中的行时,第二个网格必须显示用户的产品,而无需连接到服务器.我所知道的是 user.products();
返回一个 Ext.data.Store
对象.所以想法是将第二个网格的存储更改为 user.products();
,但是没有这样的方法 grid.setStore()
:-)
All i want to get is when you click on the row in the first grid, the second grid must show products of the user, without connection to the server.All i know is that user.products();
returns a Ext.data.Store
object.So the idea is to change second grid's store to user.products();
, but there is no such method grid.setStore()
:-)
提前致谢
推荐答案
我认为更好的解决方案是:
I think a better solution would be to :
grid1.on('itemclick', function(view, record) {
grid2.reconfigure(record.products());
);
这篇关于ExtJS 4 动态更改网格存储的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!