如何在ExtJS视图模型中以编程方式创建公式?



在ExtJS 6.2中,我如何以编程方式创建公式?

在我的视图模型中,我添加了一个构造函数,在那里我添加了公式,试图遵循它在这里说https://forum.sencha.com/forum/showthread.php?299121-Add-Formulas-to-ViewModel-dynamically,但我的公式似乎覆盖了视图模型中已经存在的公式。此外,我添加的公式似乎也不起作用。

constructor: function(config) {
this.callParent(arguments);
const newFormula = {
test: {
bind : { bindTo : '{mystore}' },
get  : mystore => mystore.findExact('type', 'something') !== -1
}
};
this.setFormulas( {...this.getFormulas(), ...newFormula} );
}

使用这种方式,新公式与已经定义的公式一起工作,但是调用视图模型getFormulas()并不列出以前存在的公式,只列出在构造函数config中添加的公式。

constructor: function(config) {
config.formulas = config.formulas || {};
config.formulas.test = {
bind : { bindTo : '{mystore}' },
get  : mystore => mystore.findExact('type', 'something') !== -1
};
this.callParent(arguments);
}

获取已经存在的公式并合并到配置中使其工作:

constructor: function(config) {
config.formulas = {...config.formulas, ...this.config.formulas};
config.formulas.test = {
bind : { bindTo : '{mystore}' },
get  : mystore => mystore.findExact('type', 'something') !== -1
};
this.callParent(arguments);
}

最新更新