Nuri Engin
Nuri Engin

Reputation: 823

Ext JS: How to get sum of two different JSON store's values?

As you will notice belowe I'm fetching to two different stores through formulas and getting TOTALCOUNT integer values of those JSONs.

How can I get sum of those two different 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.
       }       
    }

Upvotes: 2

Views: 86

Answers (1)

Evan Trimboli
Evan Trimboli

Reputation: 30092

You can bind to formulas the same as you can with anything else:

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

Also, you should change the return type in your other formulas, not sure why you would return a string there.

Upvotes: 3

Related Questions