【问题标题】:How to get the associated store in Sencha Touch?如何在煎茶触控中获得关联商店?
【发布时间】:2015-09-21 13:26:54
【问题描述】:

您好,我正在使用 Sencha Touch 应用程序,我在一个名为“客户”的商店中关联了一个模型,我知道当您创建关联模型时,您会自动在后台创建一个新商店,我的问题是:如何让这个名为“templatesStore”的商店(我在 Chrome 控制台中看到结果)稍后过滤?

提前谢谢你。

【问题讨论】:

    标签: javascript extjs sencha-touch


    【解决方案1】:

    可以使用以下语法来完成:

    <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;
            }
         }
     ]);
    

    【讨论】:

    • 用您的代码明确地获取关联商店的值,但我现在的问题是,如何根据子/关联商店的过滤器过滤父商店?
    • 你能再解释一下吗,可能有一些简单的例子
    • 例如,我有一个有客户的商店,但是根据客户的不同,您可以有模板或没有模板。在组合中我有不同的模板名称,我应该按模板过滤并得到列表中显示的客户数量。
    猜你喜欢
    • 2023-03-28
    • 1970-01-01
    • 2013-12-18
    • 1970-01-01
    • 1970-01-01
    • 2012-06-22
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多