ExtJS 6.2更新时绑定视图模型的问题
绑定视图模型时,ExtJS 6.2中有一个问题。我想在提交表单时自动更新模型。这是我的视图模型:ExtJS 6.2更新时绑定视图模型的问题,extjs,data-binding,viewmodel,Extjs,Data Binding,Viewmodel,绑定视图模型时,ExtJS 6.2中有一个问题。我想在提交表单时自动更新模型。这是我的视图模型: Ext.define('..model.OperationProperty', { idProperty: 'ObjectID', binding: { deep: true }, fields: [ { name: 'ID', type: 'integer'
Ext.define('..model.OperationProperty', {
idProperty: 'ObjectID',
binding: {
deep: true
},
fields: [
{
name: 'ID',
type: 'integer'
},
{
name: 'Operation',
type: 'auto'
},
{
name: 'OperationForInvoice',
type: 'auto'
}
]
});
操作和发票操作是不同的模型
我成功加载数据,就像
viewmodel.setData({
operationproperty: operationproperty
});
operationproperty.load();
这是我在容器中的复选框
{
xtype: 'container',
layout: {
type: 'vbox',
pack: 'center',
align: 'middle'
},
items: {
xtype: 'checkbox',
bind: {
data: {
value: '{operationproperty.Operation.IsExplanationNecessary}',
deep: true
}
}
//bind: "{operationproperty.Operation.IsExplanationNecessary}",
//deep: true,
//bind: {
// value: "{showIsExplanationNecessary}"
//}
//bind: {
// Operation: {
// bindTo: '{operationproperty.Operation.IsExplanationNecessary}',
// deep: true
// }
//}
}
及
加载数据后。已加载发票模型的操作和操作,并且“我的”复选框看起来已选中。
但是,当我在表单中创建某些内容时,例如取消选中复选框,更改不会显示在视图模型上,但操作对象会显示在视图模型的底部,仅包含更改的项。
我也搜索“deep:true”,但它不起作用,或者我找不到正确的使用方法。我尝试在视图模型中使用公式,我给出了相同的结果,它给出了相同的结果
formulas: {
showIsExplanationNecessary: {
bind: {
bindTo: '{operationproperty.Operation.IsExplanationNecessary}',
deep: true
},
get: function (get) {
return get;
},
set: function (value, type) {
debugger;
this.set('operationproperty.Operation.IsExplanationNecessary', value); //not set the field and add Operation object again
}
}
}
我希望有人能帮忙,谢谢。我通过更改公式的设置部分解决了这个问题。新的公式将是这样的
showIsExplanationNecessary: {
get: function (get) {
var operation = get('operationproperty.Operation');
if (operation == null || operation.IsExplanationNecessary == null)
return false;
if (operation.IsExplanationNecessary != null) {
return operation.IsExplanationNecessary;
}
return false;
},
set: function (value, type) {
this.getData().operationproperty.getData().Operation.IsExplanationNecessary = value;
}
}
如果该问题存在其他解决方案,请通知我。
感谢您抽出时间。您提供的数据不足,无法分析您的问题。在您的代码片段中,不清楚本机对象是如何显示的
operationproperty.Operation
,并且模型不是从类Ext.data.model
继承的。请创建FIDLE,它应该会显示您的问题。我根据您的数据创建了一个示例,但它工作得很好。您的示例为operationproperty对象添加了必要的IsExplanation。这就像我的问题一样。我需要operationproperty内的Operation对象中的IsExplanationRequired项以及更新的值。我将尝试创建小提琴。