如何获取和修改/替换/删除事件监听器

时间:2016-10-26 14:00:43

标签: events sapui5

我正在扩展SAP标准的Fiori应用程序。他们有一种创建sap.m.ViewSettingsDialog的方法。现在我正在添加自己的sap.m.ViewSettingsItem,其中包含一些sap.m.ViewSettingsFilterItem s。

现在我想在事件confirm上修改/替换/删除监听器,因为我不能像SAP那样将绑定的ODataModel中的值保存到CusomObject上。

我的尝试是加强他们的确认方法。我搜索了SCN,Stackoverflow和SAPUI5 API以获取eventhndlers的getter,我没有找到任何东西。那我怎么能得到那个对象呢?

为了进一步了解我的问题:

他们的确认方法:

              confirm: function (oEvent) {
            //reset the buffered filter arrays
            self.filterValueArray.length = 0;              
            var p = oEvent.getParameters(),
                aFilters,
                oCallback;

            for (var i = 0 ; i < p.filterItems.length; i++) {
                if (p.filterItems[i] instanceof sap.m.ViewSettingsCustomItem) { // custom control filter
                    oCallback = p.filterItems[i].getCustomData()[0].getValue();
                    aFilters = oCallback.apply(this, [p.filterItems[i].getCustomControl()]);
                    if (aFilters) {
                        // the filter could be an array of filters or a single filter so we transform it to an array
                        if (!Array.isArray(aFilters)) {
                            aFilters = [aFilters];
                        }
                        self.filterValueArray = self. filterValueArray.concat(aFilters);
                    }
                } else if (p.filterItems[i] instanceof sap.m.ViewSettingsItem) { // standard filter
                    aFilters = p.filterItems[i].getCustomData()[0].getValue();
                    if (aFilters) {
                        // the filter could be an array of filters or a single filter so we transform it to an array
                        if (!Array.isArray(aFilters)) {
                            aFilters = [aFilters];
                        }
                        self.filterValueArray = self.filterValueArray.concat(aFilters);
                    }
                }
            }

            // apply filters to the table binding
            self._updateList(self.getList().getBinding("items"));

            // update info toolbar
            self.getView().byId("infoBarToolbar").setVisible((self.filterValueArray.length > 0) ? true: false);
            self.getView().byId("infoBarFilter").setText((self.filterValueArray.length > 0) ? p.filterString: "");  

            // save expiry filter state for the "cancel" action
            self._setExpiryFilterState();                       
        }

我添加了过滤器

var oBindingInfo = {
            path: "/PathToTheKeyValuePairs",
            template: new sap.m.ViewSettingsItem({
                key: "{Key}",
                text: "{Value}",
                customData: new sap.ui.core.CustomData({
                    key: "callback",
                    value: function(oControl) {
                        debugger; //getting the data and creating filter here
                    }

                 //That would be the SAP Solution Sap does with hardcoded Filter

                    // key: "filter",
                    // value: new sap.ui.model.Filter("TargetAttribute", sap.ui.model.FilterOperator.EQ, "{Key}") //fixme It takes the string and no binding info
                })
            })
        };

        var oMyCustomFilter = new sap.m.ViewSettingsFilterItem({
            key: "myCustomFilter",
            text: self.resourceBundle.getText("myFilterName"),
        });


        oMyCustomFilter.bindAggregation("items", oBindingInfo);
        this.filterDialog.addFilterItem(oMyCustomFilter);

1 个答案:

答案 0 :(得分:1)

我建议使用attachEventattachEventOnce添加要在confirm事件中另外调用的函数:

oDialog.attachEventOnce("confirm", fnAfterConfirm);

其中oDialogViewSettingsDialog

请参阅sap.ui.base.EventProvider的API指南。