0
我試圖將odata值加載到數組中以便稍後進一步計算。下面是正確的代碼,但它看起來很乏味。我做對了嗎?它有更好的方法來做到這一點?sapui5 odata進入數組
var x = this.getView();
x.setBusy(true);
sap.List = [];
var oModelTriptab = new sap.ui.model.odata.ODataModel("XXXX");
sap.ui.getCore().setModel(oModelTriptab);
var oBinding = oModelTriptab.bindList("/List");
var tempArray = [];
var handler = function(oEvent){
oBinding.detachChange(handler);
tempArray = oEvent.oSource.getContexts();
jQuery.each(tempArray , function(i, val) {
var obj = val.getObject();
sap.List[obj.Id] = obj.Name;
console.log("TEST " + obj.Id + ":" + sap.RegCo1s[obj.Id]);
});
x.setBusy(false);
};
// call OData service and handle results
oBinding.attachChange(handler);
oBinding.getContexts();