【问题标题】:Ext JS: How to get sum of two different JSON store's values?Ext JS:如何获得两个不同 JSON 存储值的总和?
【发布时间】:2018-09-11 15:28:37
【问题描述】:

正如您将在下面注意到的那样,我正在通过formulas 获取两个不同的商店并获取这些 JSON 的 TOTALCOUNT 整数值。

如何获得这两个不同stores 的总和?

formulas: {
        firstStore: {
            bind: {
                bindTo: '{firstStatStore}',
                deep : true
            },
            get: function (store) {
                var record = store.findRecord(MyApp.Names.CODE, MyApp.Names.TOTALSTAT);
                return record ? record.get(MyApp.Names.TOTALCOUNT) : "-1";
            }
        },

        secondStore: {
            bind: {
                bindTo: '{secondStatStore}',
                deep : true
            },
            get: function (store) {
                var record = store.findRecord(MyApp.Names.CODE, MyApp.Names.TOTALSTAT);
                return record ? record.get(MyApp.Names.TOTALCOUNT) : "-1";
            }
        },

       thirdStore: {
                // Here I need "sum of TOTALCOUNT" from firstStore and secondStore.
       }       
    }

【问题讨论】:

    标签: javascript json extjs formulas extjs-stores


    【解决方案1】:

    您可以像绑定其他任何东西一样绑定到公式:

    thirdStore: function(get) {
        return get('firstStore') + get('secondStore');
    }
    

    另外,您应该更改其他公式中的返回类型,不知道为什么要在那里返回一个字符串。

    【讨论】:

      猜你喜欢
      • 2011-09-19
      • 2014-01-15
      • 2023-04-05
      • 1970-01-01
      • 1970-01-01
      • 2019-09-17
      • 1970-01-01
      • 2018-08-26
      • 1970-01-01
      相关资源
      最近更新 更多