我目前正在学习 SAP UI5,我找不到有关如何在 sap.m.Select
中显示项目的足够信息,我想做的是显示我自己的数组中的项目作为下拉菜单并向所有这些添加 anchor 链接,例如:
var myMenuItems = ["foo","bar","baz"];
我设法构建了一个选择菜单
,但没有找到添加项目的方法,所以它现在看起来是空的。
我的选择代码是:
new sap.m.Select(this.createId("selector"), {
name:"selectName",
selectedKey: "foo",
icon: "sap-icon://navigation-down-arrow",
valueState:"Success",
valueStateText:"random text idk what for",
forceSelection:false
})
如何推送 myMenuItems
的项目并在此 Select
中显示它们?
最佳答案
sap.m.Select 是一个非常强大的控件。正如阿什提到的,你需要一个模型。 这是您的案例的一个工作示例:
<!DOCTYPE HTML>
<html>
<head>
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<meta charset="utf-8">
<script src="https://openui5.hana.ondemand.com/resources/sap-ui-core.js"
id="sap-ui-bootstrap"
data-sap-ui-libs="sap.m"
data-sap-ui-theme="sap_belize"></script>
<script>
var oData = {
MenuItems: [{id: 1,name: "foo"},{id: 2,name: "bar"},{id: 3,name: "baz"}]
};
var oModel = new sap.ui.model.json.JSONModel(oData);
var oSelect = new sap.m.Select({
id: "selector",
});
var oItemSelectTemplate = new sap.ui.core.Item({
key: "{id}",
text: "{name}"
}); //Define the template for select items
oSelect.setModel(oModel);// set model to Select element
oSelect.bindAggregation("items", "/MenuItems", oItemSelectTemplate); //bind aggregation with the template to items
oSelect.placeAt('content');
</script>
</head>
<body id="content" class="sapUiBody">
</body>
</html>
关于javascript - 在 sap -select 中显示数组项目并向项目添加 anchor 标记,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/46463811/