我有一个sap.m.Table,它的“项”绑定到oData v2模型。我需要删除项目点击删除图标。下面是我所做的工作:单击delete图标,获取模型中的所有行,删除其中的行,并再次设置模型的属性。但是,由于模型被更改,它将触发后端往返,并带来最新的数据和表,再次显示原始行。
我尝试将绑定模式设置为OneTime,但这不起作用。还尝试将RefreshAfterChange设置为false,但即使这样,服务也再次被调用。
这是我的密码-
控制器
onInit: function() {
var oModel = new sap.ui.model.odata.v2.ODataModel("url", {
json: true,
useBatch : false,
refreshAfterChange: false,
defaultBindingMode: "OneTime"
});
this.getView.().setModel(oModel, "model1");
},
onDeleteIconPress : function(oEvent) {
// get the selected row
// get all the rows in oOriginalRows
// loop over oOriginalRows and delete the selected row from it
// set the model to reformed oOriginalRows
this.getView().getModel("omodel1").setProperty("/", oOriginalRows);
// Till this point every thing looks fine. I can see changes in the model
// refresh is called automatically and data service triggers backend call
// This fetches original data again and table shows all data again
}
我怎么能不触发往返旅行呢?我需要在本地更新
发布于 2017-01-19 13:20:35
因为Odata是服务器端模型,所以它总是触发往返。因此,我没有将我的sap.m.Table绑定到数据模型。相反,我手动触发了一个读取。成功后,我将收到的数据复制到本地JSON模型中。我将表项绑定到这个JSON模型。现在,删除按钮工作得很好。
// Define a JSON Model
oJsonModel = new sap.ui.model.json.JSONModel();
//oModel is Odata model defined in manifest file
oModel.read("/entity1", {
success: function(oData, oResponse){
oJsonModel.setProperty("/entity1", oData.results);
// bind oJsonModel to table here
}
}
发布于 2017-01-16 00:50:44
您的方法不适用于ODataModel,因为它是严格的服务器端。请使用相应的删除方法从服务器中删除实体。
https://stackoverflow.com/questions/41666601
复制相似问题