从responpopup的事件函数内的控制器调用函数

时间:2016-07-28 06:34:06

标签: sapui5 sap-fiori

我有一个在“删除”模式下包含列表的responsivepopup。 当我单击删除项目时,按下时会调用一个函数。 使用此函数'this'是oList,oEvent.oSource也是oList。 在事件函数中,我需要在我的控制器中调用一个函数。 我找不到引用我的控制器的方法,甚至没有使用sap..core..byId(“Detail”)甚至是完整的命名空间。 我尝试从oEvent.oSource.getParent()。getParent()走到elemnt树然后调用.getController(),但这是一个死胡同。

        handlePressViewSelection: function(oEvent) {
        var oResourceBundle = this.getResourceBundle();

        //create the list
        var oList = new sap.m.List({
            mode: "Delete",
            delete: this.handleDeleteSelectionItem
        });

        oList.setModel(this._oSelectedTrainingsModel);

        var oItemTemplate = new sap.m.StandardListItem({
            title : "{Title}",
            description : "{=${Begda} ? ${Type} - { path: 'Begda', type: 'sap.ui.model.type.Date', formatOptions: { style: 'medium' }} : ${Type}}",
            icon : "{icon}",
            iconInset : false
        });

        oList.bindAggregation("items", {
            path: "/",
            template: oItemTemplate,
            type: "Active"
        });

        var oBeginButton = new sap.m.Button({
            text: "Action1",
            type: sap.m.ButtonType.Reject,
            press: function(){
                oResponsivePopover.setShowCloseButton(false);
            }
        });
        var oEndButton = new sap.m.Button({
            text: "Action2",
            type: sap.m.ButtonType.Accept,
            press: function(){
                oResponsivePopover.setShowCloseButton(true);
            }
        });

        var oResponsivePopover = new sap.m.ResponsivePopover({
            placement: sap.m.PlacementType.Bottom,
            title: "",
            showHeader: false,
            beginButton: oBeginButton,
            endButton: oEndButton,
            horizontalScrolling: false,
            content: [
                oList
            ]
        });

        oResponsivePopover.openBy(oEvent.oSource);
    },

        handleDeleteSelectionItem: function(oEvent) {
        var oListItem = oEvent.getParameter('listItem');
        var oList = oListItem.getParent();
        var path = oListItem.getBindingContext().sPath;
        oList.getModel().getData().splice(parseInt(path.substring(1)), 1);
        oList.removeItem(oEvent.getParameter('listItem'));
        oList.getParent().getParent().getController()._updateViewSelectionButtonText(); //--> BROKEN
    },

1 个答案:

答案 0 :(得分:0)

从片段中实例化弹出窗口时,可以指定“片段中用于事件处理程序的控制器”(参见https://sapui5.hana.ondemand.com/#docs/api/symbols/sap.ui.html#.xmlfragment

例如:

onOpenResponsivePopover : function(oEvent) {

    if (!this._oResponsivePopover) {
        // adding 'this' makes sure you specify the current controller to be used for event handlers 
        this._oResponsivePopover = sap.ui.xmlfragment("namespace.to.your.popoverfragment", this); 
        this.getView().addDependent(this._oResponsivePopover);
    }

    this._oResponsivePopover.openBy(oEvent.getSource());
},