首页 > 解决方案 > 如何为片段分配控制器?

问题描述

我有以下视图,其中包含一个片段:

<mvc:View xmlns:core="sap.ui.core" xmlns:mvc="sap.ui.core.mvc" xmlns="sap.m" xmlns:smartFilterBar="sap.ui.comp.smartfilterbar"
    controllerName="ch.mindustrie.ZMM_OBJECTS_CLASSES.controller.ClassSelection" xmlns:html="http://www.w3.org/1999/xhtml">
    <smartFilterBar:SmartFilterBar id="SelectionFilterBar" entitySet="ZMM_C_CLASSIFICATION" search="onSearchClass">
        <smartFilterBar:controlConfiguration>
            <smartFilterBar:ControlConfiguration key="ClassType" preventInitialDataFetchInValueHelpDialog="false"></smartFilterBar:ControlConfiguration>
            <smartFilterBar:ControlConfiguration key="ClassNum" preventInitialDataFetchInValueHelpDialog="false"></smartFilterBar:ControlConfiguration>
        </smartFilterBar:controlConfiguration>
    </smartFilterBar:SmartFilterBar>
    <core:Fragment fragmentName="ch.mindustrie.ZMM_OBJECTS_CLASSES.fragment.Tree" id="TreeFm" type="XML"/>
</mvc:View>  

然后,我想为片段分配一个控制器:

sap.ui.define([
    "ch/mindustrie/ZMM_OBJECTS_CLASSES/controller/BaseController",
    "ch/mindustrie/ZMM_OBJECTS_CLASSES/helper/Message",
    "ch/mindustrie/ZMM_OBJECTS_CLASSES/controller/TreeFragment.controller"
], function (BaseController, Message, TreeController) {
    "use strict";

    return BaseController.extend("ch.mindustrie.ZMM_OBJECTS_CLASSES.controller.ClassSelection", {
        onInit: function () {

        },

        onSearchClass: function () {
            const aFilter = this.byId("SelectionFilterBar").getFilters();
        },
    });
});   

TreeController控制器应分配给具有上述 id 的片段TreeFm。如何将控制器分配给片段?

我考虑了功能sap.ui.core.Fragment.load,但我认为它不适合我的情况。

标签: sapui5

解决方案


推荐阅读