Search code examples
extjsmvvmbindformulastore

Bind formula for changes in store


I am have formula and want execute it when store in this viewModel is changeData.

When I do this, the formula does not work when data in store changed

stores: {

    currentStore: {
        extend: 'Ext.store.MyStore',
        trackRemoved: false
    },
    },
    formulas: {

    'executeWhenStoreChange': {
        bind: '{currentStore}',

        get: function () {
           console.log('store change')
    },

Solution

  • If you're looking to fire a function when data changed I would use a datachanged listener to the store(s) you want the event to fire on.

        currentStore: {
            listeners: {
                datachanged: function(store, eOpts) {
                    console.log('store change');
                }
            }
        },
    

    If you want it for all stores just reference the function in each datachanged listener

        currentStoreA: {
            listeners: {
                datachanged: 'onStoreDataChangeD'
            }
        },
        currentStoreB: {
            listeners: {
                datachanged: 'onStoreDataChangeD'
            }
        },
    

    Then in the view controller:

        onStoreDataChangeD: function(store, eOpts) {
        console.log('store changed');
    }