结果最初显示在文本控件中,然后乘以从 Odata 加载并显示在输入控件中的价格和数量。目标是,在将新价格和新数量输入到输入控件后,结果应在该文本控件中自动更新。使用 _onChange() 我可以更改 OData 的属性(在本例中是价格和数量)(我已经看到更新的属性并导致调试器模块)。但是更新后的结果并没有显示在文本控件中,有人知道吗?
XML:
<t:Column>
<Text text="Price"/>
<t:template>
<Input id="price" value="{Prc}" editable="true" change="_onChange"/>
</t:template>
</t:Column>
<t:Column>
<Text text="Quantity"/>
<t:template>
<Input id="quantity" value="{Qty}" editable="true" change="_onChange"/>
</t:template>
</t:Column>
JS:
_onChange: function(oEvent){
var test = oEvent.getSource();
var path = test.getBindingContext().getPath();
var obj = oModel.getProperty(path);
var stringID=test.sId;
//determine the current control using the predefined ID
switch(oEvent!=null){
case stringID.match("quantity")!=null
//read the Input of quantity in Input control
obj.Qty = test._$input.context.value;
break;
case stringID.match("price")!=null:
//read the input of price in Input control
obj.Prc = test._$input.context.value;
break;
};
var sum = parseInt(obj.Prc) * parseInt(obj.Qty);
obj.Result =sum.toString();
}
最佳答案
如果您在模型中绑定(bind)了 RESULT,请使用它来更新模型。
关于javascript - 使用 JS 和 XML 更改文本控件中的 OData 值,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/46040149/