使用 JS 和 XML 更改文本控件中的 OData 值
Change OData value in Text control using JS and XML
结果最初显示在文本控件中,然后乘以从 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();
}
如果您在模型中绑定了 RESULT,请使用它来更新模型。
我已经解决了问题。
问题是:我为输入定义的控件 ID(在本例中为 id="quantity"
),oEvent 无法找到它,因为控件 ID 是动态生成的(在本例中为例如:id="__xmlview1--TBL_ep"
).为了找到这个动态id,我们需要使用var oSTBL_EP = this.getView().byId("quantity");
,而不是调用oSTBL_EP的属性 sId。
只有有效的Id,该值才能在文本控件中可见
结果最初显示在文本控件中,然后乘以从 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();
}
如果您在模型中绑定了 RESULT,请使用它来更新模型。
我已经解决了问题。
问题是:我为输入定义的控件 ID(在本例中为 id="quantity"
),oEvent 无法找到它,因为控件 ID 是动态生成的(在本例中为例如:id="__xmlview1--TBL_ep"
).为了找到这个动态id,我们需要使用var oSTBL_EP = this.getView().byId("quantity");
,而不是调用oSTBL_EP的属性 sId。
只有有效的Id,该值才能在文本控件中可见