首页 > 解决方案 > 如何在对话框中获取选定值作为文本

问题描述

我有一个简单的表格如下:

    <f:SimpleForm layout="ResponsiveGridLayout">
      <f:content>
        <m:Select id="Employee" items="{Employee>/EmployeeList}" change="onEmployeechange">
          <c:Item key="{key}" text="{value}" />
          <m:layoutData>
            <l:GridData span="L2 M2 S2"/>
          </m:layoutData>
        </m:Select>
      </f:content>
    </f:SimpleForm> 

我将从后端获取员工列表(即员工姓名)。当我们从下拉列表中选择任何一个员工姓名时,将打开一个对话框,我的控制器如下:

    onEmployeechange: function() {
      this.oDialog = new sap.m.Dialog({
        title: "EmployeeList",
        contentWidth: "40px",
        contentHeight: "300px",
        content: [
          new sap.m.Text({
            width: "100%",
            text: "Employee Name" // here i want to get the selected employee name from the simple form as text in dialog box 
          }),
          new sap.m.Text({ width: "100%", text: "City" }),
          new sap.m.FlexBox({
            justifyContent: "Center",
            items: [
              new sap.m.Select("cityId", {
                width: "60%",
                items: {
                  path: '/Employee/City',
                  template: new sap.ui.core.Item({
                    key: '{key}',
                    text: '{value}'
                  })
                }
              })
            ]
          }),
        ],
      });
    }

I want to achieve as above image
在此处输入图像描述
提前感谢任何帮助或指导链接

标签: sapui5

解决方案


添加 oEvent 参数后,您可以在需要时访问所选值甚至键。我想这是你的要求。请澄清这是否不是您所需要的。

onEmployeechange: function(oEvent) {
    var sName = oEvent.getSource().getSelectedItem().getText();
    this.oDialog = new sap.m.Dialog({
        title: "EmployeeList",
        contentWidth: "40px",
        contentHeight: "300px",
        content: [
            new sap.m.Text({
                width: "100%",
                text: sName
            }), // here i want to get the selected employee name from the simple form as text in dialog box 

            new sap.m.Text({
                width: "100%",
                text: "City"
            }),
            new sap.m.FlexBox({
                justifyContent: "Center",
                items: [
                    new sap.m.Select("cityId", {
                        width: "60%",
                        items: {
                            path: '/Employee/City',
                            template: new sap.ui.core.Item({
                                key: '{key}',
                                text: '{value}'
                            })
                        }
                    })
                ]
            }),
        ]
    })
}

推荐阅读