我想从sapui5(xml视图和JS控制器)中的输入列表项(绑定到JSON模型)中获取数据
Shape of the list, fetch data from the square brackets and quantity input field
答案 0 :(得分:1)
getBindingContext
以获取绑定上下文。getObject
以获取绑定到该列表项的模型数据。在您的情况下,作为示例,您可以在liveChange
处理程序中获取数据:
handleLiveChange: function(event) { // from Input
const myInputControl = event.getSource(); // e.g. the first item
const boundData = myInputControl.getBindingContext().getObject();
/* returns: {
i_Category: "Proteins",
i_Points: 10,
i_Category_ID: "PRT"
} */
},
有关进一步的解决方案,请参阅下面的讨论。
答案 1 :(得分:0)
为boghyan 提到(如果我错了,请纠正我)
// getting the current context for the list
var myContexts = this.byId("createOrder--orderList").getBinding("items").getCurrentContexts();
// get object binded to the context
var myBoundDataObjects = myContexts.map(function(context) {
return context.getObject();
});
// looping on the bounded data to change the values of the JSON Array
for (var i = 0; i < myBoundDataObjects.length; i++) {
if (myBoundDataObjects[i].i_Category_ID === categoryID) {
myBoundDataObjects[i].i_Quantity = parseInt(Qty, 10);
break;
}
}
// setting the json model in order to pass it to different methods/classes
var ordersModel = new JSONModel(myBoundDataObjects);
sap.ui.getCore().setModel(ordersModel , "ordersModel");