Javascript 使用SAPUI5在下拉列表中选择默认值
在SAPUI5的下拉框中设置默认值时,我遇到了一个问题 目前我正在使用以下代码:Javascript 使用SAPUI5在下拉列表中选择默认值,javascript,sapui5,Javascript,Sapui5,在SAPUI5的下拉框中设置默认值时,我遇到了一个问题 目前我正在使用以下代码: fields : [ new sap.ui.commons.DropdownBox("Cities", { selectedKey: "City3", items : [ new sap.ui.core.ListItem("City1", { text : "DE (Germany)" }), new sap.ui.core.ListItem("City2", { t
fields : [ new sap.ui.commons.DropdownBox("Cities", {
selectedKey: "City3",
items : [ new sap.ui.core.ListItem("City1", {
text : "DE (Germany)"
}), new sap.ui.core.ListItem("City2", {
text : "GB (United Kingdom)"
}), new sap.ui.core.ListItem("City3", {
text : "IN (India)"
}), new sap.ui.core.ListItem("City4", {
text : "US (United States)"
}) ]
})
}) ]
但在列表框中,它总是显示DE(Germany)
值,但我想默认设置其他值
如何做到这一点?所有
sap.ui.core.Item
s都有一个名为key
的属性,您可以在下拉框中引用该属性
new sap.ui.core.ListItem("City1", {
key : "City1",
text : "DE (Germany)"
})
否则,您可以尝试使用
selectedItemId
而不是selectedKey
如果您使用key
和name
sap.ui.getCore().byId('Cities').setSelectedItemId('YOUR ITEM ID')
//如果您使用的是键值对,那么
sap.ui.getCore().byId('Cities').setSelected('YOUR ITEM ID').setSelectedKey('YOUR KEY VALUE(1/2/3..)')
使用selectedItemId可以正常工作。你说过我们也可以在下拉框中通过引用做同样的事情。你能给我举个例子吗?