从商店监听器获取 ViewModel

Get ViewModel from stores listeners

我有 viewModel:

Ext.define('Shop.view.BooksViewModel', {
extend: 'Ext.app.ViewModel',

alias: 'viewmodel.booksVM',

stores: {
    books: {
        model: 'Poly.model.books',
        extend: 'Ext.data.Store',
        listeners: {
            update: function() {
                // get this view model for set record in 'getBooks' formula
            }
        }
    }
},

formulas: {
    getBooks: {
        get: function (value) {

            return value;
        }
    }
}})

并且在商店的 'update' 函数中我想要获取此 viewModel 并在公式记录中设置。 但是如果我在商店功能中调用 'this' 我会得到 'store'

使用 initConfig 方法。

Ext.define('Shop.view.BooksViewModel', {
extend: 'Ext.app.ViewModel',

alias: 'viewmodel.booksVM',

initConfig: function(instanceConfig) {
    var me = this,
        config = {
            stores: {
                books: {
                    model: 'Poly.model.books',
                    extend: 'Ext.data.Store',
                    listeners: {
                        update: function() {
                            console.log(me.getFormulas().getBooks);
                        }
                    }
                }
            }
        };
    if (instanceConfig) {
        me.getConfigurator().merge(me, config, instanceConfig);
    }
    return me.callParent([config]);
},

formulas: {
    getBooks: {
        get: function (value) {

            return value;
        }
    }
}})