Sapui5:模型不被破坏
问题描述:
在下面的代码我尝试,如果它存在破坏JSON模式:Sapui5:模型不被破坏
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"));
日志是:
第1段(在这里我试图摧毁模型):
C.extend.constructor {mEventRegistry: Object, oData: Object, bDestroyed: false, aBindings: Array[0], mContexts: Object…}
第二个片段(其中模型设置):
EventProvider sap.ui.model.json.JSONModel
我在这里错过了什么?为什么日志如此不同?
这个问题的主要问题是我试图摧毁那个模型,但它不起作用。
答
我检查了API here,它表示Model实现可能会干扰destroy函数。 我与我的模型有相同的结果,当我试图删除它时,所有删除的都是绑定,但不是整个模型。
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…}
从上面的代码示例中可以看到。我会继续寻找,但我想这是不可能删除整个模型。
+0
在SAP博客上找到类似的thrad - https://archive.sap.com/discussions/thread/3534349。从核心作品中取消设置模型 - 设置模型,如果您没有给出任何名称,则使用'sap.ui.getCore()。setModel();' 这将覆盖旧模型。 既然你有一个名字,这次传递null。这是 'sap.ui.getCore()。setModel(null,'userModel');' – user557657
你确定“sap.ui.getCore()。getModel(”modelId“)”实际返回一个模型吗?此对象是否具有属性“destroy()”?您可以使用console.log(sap.ui.getCore()。getModel(“modelId”));如果你不知道。 – OddDev