sapui5 - 如何在对话框中获取选定值作为文本
问题描述
我有一个简单的表格如下:
<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}'
})
}
})
]
}),
],
});
}
解决方案
添加 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}'
})
}
})
]
}),
]
})
}
推荐阅读
- spring-webflux - 在 Spring Webflux 中捕获响应
- c++ - 如何修复对象在被释放后可能修改的 malloc 错误
- python - 如何优化这个 dijkstra 的算法?
- android - 无法为匕首注入提供上下文
- c++ - 变量无法清晰
- html - 是否可以在 office.com/myaccount 中找到最后一个 Office 的产品密钥?
- java - CheckBox 仅返回 false 即使它被选中(勾选)
- node.js - 在 Docker 容器中访问 Angular 应用程序
- sql - 列名称以 Amazon Athena 中的数字处理开头
- angular - 为什么 *ngIf 需要“必需”验证器才能工作?