Sapui5:模型没有被破坏

时间:2015-05-04 08:14:53

标签: javascript sapui5

在下面的代码中,我尝试销毁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

我在这里缺少什么?为什么日志如此不同?

这个问题的主要问题是我试图破坏该模型,但它不起作用。

1 个答案:

答案 0 :(得分:1)

我检查了API here,它说模型实现可能会干扰销毁功能。 我和我的模型有相同的结果,当我试图删除它时,所有删除的都是Bindings,但不是整个模型。

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…}

从上面的代码示例中可以看出。我会一直看,但我想不可能删除整个模型。