Fragment not get correct Controller

2019-09-06 16:50发布

问题:

I istantiate a fragment by this code in the controller formAddElement. (i use this to pass current controller)

this._oDialog = sap.ui.xmlfragment("apps.appIntra.fragment.dialogClienti",this);

In the same controller i have a function handleSearch

handleSearch: function(oEvent) {
        var sValue = oEvent.getParameter("value");
        var oFilter = new sap.ui.model.Filter("RAG_SOC_1", sap.ui.model.FilterOperator.Contains, sValue);
        var oBinding = oEvent.getSource().getBinding("items");
        oBinding.filter([oFilter]);
  },

when in the fragment i press search the function in the controller not fire.

But if I use

this._oDialog = sap.ui.xmlfragment("apps.appIntra.fragment.dialogClienti", sap.ui.getCore().byId('formAddElement').getController());

all work!! WHY??? O_o

回答1:

"this" should work. you need to run F12 debugger in chrome to check what "this" is, whether it is the oController object. it could be other object depending the calling object.



标签: sapui5