绑定商店中更改的公式

use*_*654 1 bind extjs store formula mvvm

我有公式,并希望执行它时,店这viewModelchangeData

当我这样做时,当存储中的数据发生变化时,公式不起作用

stores: {

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

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

        get: function () {
           console.log('store change')
    },
Run Code Online (Sandbox Code Playgroud)

小智 5

如果您希望在数据更改时触发函数,我将使用datachanged您希望事件触发的商店的侦听器。

    currentStore: {
        listeners: {
            datachanged: function(store, eOpts) {
                console.log('store change');
            }
        }
    },
Run Code Online (Sandbox Code Playgroud)

如果您希望所有商店都使用它,只需在每个datachanged侦听器中引用该函数

    currentStoreA: {
        listeners: {
            datachanged: 'onStoreDataChangeD'
        }
    },
    currentStoreB: {
        listeners: {
            datachanged: 'onStoreDataChangeD'
        }
    },
Run Code Online (Sandbox Code Playgroud)

然后在视图控制器中:

    onStoreDataChangeD: function(store, eOpts) {
    console.log('store changed');
}
Run Code Online (Sandbox Code Playgroud)