控制器的 XML 片段事件绑定不起作用



我的UI5应用程序和一个简单的表单有问题。如所探索的应用示例所示。

这种情况是,按 edit 会将页面的内容替换为片段的其他 SimpleForm(控制器中的代码隐藏)。

也是这样做的;唯一的区别是我只是将 SimpleForm 的内容替换为存储在 XML 片段中的控件。

现在我有一个按钮,该按钮应绑定到底层控制器。但是,当您在代码隐藏中执行此操作时,控制器上的事件将不再触发。当我在 xml 视图定义文件中使用该片段时,它有效,但现在它没有了。

controllerModelPropertyChanged(oEvent: sap.ui.base.Event) {
            let cdata = (oEvent.getSource() as any).getData() as agenttemplatesdetailcontroller;
            let p = this.byId("form") as sap.ui.layout.form.SimpleForm;
            for(let c of p.getContent())
                c.destroy();
            p.removeAllContent();
            let f = sap.ui.xmlfragment("ifm.datalink.linerecorder.ams.frontend.view.fragments.agentTemplates."+ (cdata.edit ? "AgentTemplateDetailsEdit" : "AgentTemplateDetailsDisplay")) as sap.ui.core.Control[];
            f.forEach((v) => { p.addContent(v); });
        }

添加控件时,是否未绑定到控制器的绑定事件?我必须手动绑定它们吗?

编辑:

显示片段:

<core:FragmentDefinition
        xmlns="sap.m"
        xmlns:core="sap.ui.core"
        xmlns:u="sap.ui.unified">
      <Label text="{i18n>templates.details.name}"/>
      <Text text="{template>/Name}" enabled="{form>/enabled}"/>
      <Label text="{i18n>templates.details.description}"/>
      <Text text="{template>/Description}" editable="{form>/enabled}"/>
      <List headerText="{i18n>templates.details.versionsTitle}" items="{template>/Versions}">
        <CustomListItem>
          <HBox>
            <Label text="{template>Version/Major}.{template>Version/Minor}.{template>Version/Build}"/>
            <Label text=" ({parts: [{path: 'template>CreationDate', type: 'sap.ui.model.odata.type.Date'}, {path: 'i18n>global.dateformat', type: 'sap.ui.model.type.String'}], formatter: '.odatadateformatter'})"/>
            <Label text="{ams>Guarantor/username}"/>
          </HBox>
          </CustomListItem>
      </List>
</core:FragmentDefinition>

编辑片段:

<core:FragmentDefinition
        xmlns="sap.m"
        xmlns:core="sap.ui.core"
        xmlns:u="sap.ui.unified">
      <Label text="Name"/>
      <Input value="{template>/Name}" enabled="{form>/enabled}"/>
      <Label text="Description"/>
      <TextArea value="{template>/Description}" editable="{form>/enabled}"/>
      <Label text="Upload new Version"/>
      <u:FileUploader id="fileUploader" name="MyFileUpload" uploadUrl="http://localhost:13917/api/fileupload/uploadfile" tooltip="Upload your file to the local server" uploadComplete="handleUploadComplete"/>
      <Button   text="Upload File" press="AddNewTemplateVersion"/>
      <List headerText="{i18n>templates.details.versionsTitle}" items="{template>/Versions}">
        <CustomListItem>
          <HBox>
            <Label text="{template>Version/Major}.{template>Version/Minor}.{template>Version/Build}"/>
            <Label text=" ({parts: [{path: 'template>CreationDate', type: 'sap.ui.model.odata.type.Date'}, {path: 'i18n>global.dateformat', type: 'sap.ui.model.type.String'}],
                            formatter: '.odatadateformatter'})"/>
            <!--<Label text="{ams>Guarantor/username}"/>-->
          </HBox>
          </CustomListItem>
      </List>
  </core:FragmentDefinition>

视图:

<mvc:View
        controllerName="ifm.datalink.linerecorder.ams.frontend.controller.agentTemplates.AgentTemplatesDetail"
        xmlns="sap.m"
        xmlns:core="sap.ui.core"
        xmlns:commons="sap.ui.commons"
        xmlns:f="sap.ui.layout.form"
        xmlns:l="sap.ui.layout"
        xmlns:mvc="sap.ui.core.mvc">
  <f:SimpleForm
            class="lra5form"
            minWidth="500"
            maxContainerCols="2"
            layout="ResponsiveGridLayout"
            title="{i18n>templates.details.title}"
            editable="{controller>/edit}"
            labelSpanL="3"
            labelSpanM="3"
            emptySpanL="4"
            emptySpanM="4"
            columnsL="1"
            columnsM="1"
            id="form">
    <f:toolbar>
      <Toolbar>
        <Button text="{i18n>templates.details.edit}" icon="sap-icon://edit" enabled="{= !${controller>/edit}}" press="onEditPressed" />
        <Button text="{i18n>templates.details.delete}" icon="sap-icon://delete" press="onDelete" visible="{= !${controller>/edit}}" />
        <ToolbarSpacer/>
        <Button text="{i18n>global.accept}" icon="sap-icon://accept" press="onAcceptClicked" visible="{controller>/edit}" enabled="{controller>/changed}"/>
        <Button text="{i18n>global.cancel}" icon="sap-icon://cancel" press="onCancelClicked" visible="{controller>/edit}" />
      </Toolbar>
    </f:toolbar>
    <f:content>
      <core:Fragment fragmentName="ifm.datalink.linerecorder.ams.frontend.view.fragments.agentTemplates.AgentTemplateDetailsDisplay" type="XML"/>
    </f:content>
  </f:SimpleForm>
</mvc:View>

应添加对控制器的引用以处理回调。

例:
this._oDialog = sap.ui.xmlfragment("sap.ui.demo.wt.view.HelloDialog", this);

以下是片段回调文档的链接:(https://help.sap.com/viewer/0ce0b8c56fa74dd897fffda8407e8272/7.5.5/en-US/354f98ed2b514ba9960556333428d35e.html)

最新更新