【发布时间】:2015-09-21 13:26:54
【问题描述】:
您好,我正在使用 Sencha Touch 应用程序,我在一个名为“客户”的商店中关联了一个模型,我知道当您创建关联模型时,您会自动在后台创建一个新商店,我的问题是:如何让这个名为“templatesStore”的商店(我在 Chrome 控制台中看到结果)稍后过滤?
提前谢谢你。
【问题讨论】:
标签: javascript extjs sencha-touch
您好,我正在使用 Sencha Touch 应用程序,我在一个名为“客户”的商店中关联了一个模型,我知道当您创建关联模型时,您会自动在后台创建一个新商店,我的问题是:如何让这个名为“templatesStore”的商店(我在 Chrome 控制台中看到结果)稍后过滤?
提前谢谢你。
【问题讨论】:
标签: javascript extjs sencha-touch
可以使用以下语法来完成:
<mainStore>.getAt(0).<assosiationName>();
例如,如果主商店是“客户”并且在关联中给出的名称为“模板”,则: Customer 模型中给出的关联:
hasMany: [
{
model: 'sample.model.Template',
associationKey: 'templates',
name: 'templates' // name given here will be accessed from main store
},
]
获取模板存储:
Ext.getStore('Customer').getAt(0).templatesStore;
或
Ext.getStore('Customer').getAt(0).templates();
用于根据模板值过滤“客户”商店:
Ext.getStore('Customer').filter([
{ filterFn: function (item) {
item.templatesStore.filter('templateValue',templateValue); // templateValue contains the value of selected template
if(item.templatesStore.getCount()>0)
return true;
else
return false;
}
}
]);
【讨论】: