在下面的代码中,我尝试销毁 JSON 模型(如果存在):
if(sap.ui.getCore().getModel("modelId")){
console.log(sap.ui.getCore().getModel("modelId"));
sap.ui.getCore().getModel("modelId").destroy();
};
但是上面的模型并没有被破坏。
上面的模型是在另一个函数中设置的,它看起来像这样:
var oModel = new sap.ui.model.json.JSONModel();
oModel.setData(oData);
sap.ui.getCore().setModel(oModel, "modelId");
console.log(sap.ui.getCore().getModel("modelId"));
日志是:
第一个片段(我尝试破坏模型的地方):
C.extend.constructor {mEventRegistry: Object, oData: Object, bDestroyed: false, aBindings: Array[0], mContexts: Object…}
第二个片段(设置模型的位置):
EventProvider sap.ui.model.json.JSONModel
我在这里缺少什么?为什么日志如此不同?
这里的主要问题 - 是我尝试破坏该模型,但它不起作用。
最佳答案
我检查了 API here它说模型实现可能会干扰销毁功能。 我的模型得到了相同的结果,当我尝试删除它时,所有被删除的都是绑定(bind),而不是整个模型。
var test = sap.ui.getCore().getModel("partnerDaten");
console.log(test);
if(test !== undefined){
sap.ui.getCore().getModel("partnerDaten").destroy();
this.getView('bearbeiten').getModel("partnerDaten").refresh(true);
console.log(test);
};
这些是控制台日志。
C.extend.constructor {mEventRegistry: Object, oData: Object, bDestroyed: false, aBindings: Array[46], mContexts: Object…}
C.extend.constructor {mEventRegistry: Object, oData: Object, bDestroyed: true, aBindings: Array[0], mContexts: Object…}
正如您从上面的代码示例中看到的。我会继续寻找,但我想不可能删除整个模型。
关于javascript - Sapui5:模型没有被破坏,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/30025529/