我正在使用 ExtJS 7.5.1
需要绑定 我有自定义组合框
Ext.define('vkr.components.comboboxes.DepartmentCombo', {
extend: 'Ext.form.field.ComboBox',
......
departmentTypeId: null,
bind: {
store: '{cathedra}'
},
setDepartmentTypeId: function (value) {
this.departmentTypeId = value;
},
});
视图模型
Ext.define('vkr.components.DepartmentComboViewModel', {
extend: 'Ext.app.ViewModel',
alias: 'viewmodel.department_combo',
formulas: {
departmentTypeId: {
get: function(get) {
return this.getView().departmentTypeId;
}
},
},
stores: {
cathedra: {
.......
proxy: {
......
extraParams: {
department_type_id: "{departmentTypeId}"
}
}
},
}
});
我需要从面板绑定departmentTypeId,它从视图模型数据中获取值。
{
xtype: "department_combo",
name: "department_id",
bind: {
departmentTypeId: "{department_type_id}",
},
},
在window.show方法colled之前绑定的参数(窗口中的面板)
win.getViewModel().notify();
win.getViewModel().set("department_type_id", department_type_id);
win.getViewModel().notify();
因此,在组合框视图模型中,departmentTypeId 为 null,我认为是因为 Ext 在调用 win.getViewModel().notify() 之前尝试绑定参数。如何正确设置departmentTypeId参数值
我的解决方案是添加“渲染”侦听器并从 onRender 函数设置视图模型数据值
onRender: function () {
this.lookupReference(
"PreviousDepartment"
).getViewModel().set(
"departmentTypeId", this.getViewModel().get("department_type_id")
);
},