2017-09-04 22 views
2

結果最初顯示在文本控件中,並且乘以從Odata加載並顯示在輸入控件中的價格和數量。目標是,在將新價格和新數量輸入到輸入控件後,結果應該在該文本控件中自動更新。使用_onChange()我可以更改OData的屬性(在這種情況下是價格和數量)(我已經看到更新的屬性並導致調試器模塊)。但更新的結果只是不顯示在文本控制中,有沒有人有想法?使用JS和XML更改文本控件中的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(); 
} 

回答

0

我已經解決了這個問題。 問題是:我爲輸入定義的控件ID(在本例中爲id="quantity")無法通過oEvent找到,因爲控件ID是動態生成的(在本例中爲id="__xmlview1--TBL_ep")。爲了驗證這個動態ID,我們需要使用var oSTBL_EP = this.getView().byId("quantity");,並調用oSTBL_EP的屬性sId。 只有使用有效的ID,該值才能在文本控件中可見

1

如果您在模型中的約束結果,用它來更新模型。

相關問題