<MultiComboBox id="empDropDown" items="{/emp}"
selectedKeys="{/emp/0/empNumber}">
<core:Item key="{empNumber}" text="{Name}" />
</MultiComboBox>
数据以下列格式直接绑定到模型中的数据: { “empNumber”:8683, “名称”:“A001”, “描述”:“描述1”, }
答案 0 :(得分:1)
由于我没有完全理解你想要得到什么,我在xml中做了一个简单的例子:
<MultiComboBox id="comboBoxTest" selectedKeys="key0,key1" width="150px">
<core:Item id="idName1" text="A000" key="key0" />
<core:Item id="idName2" text="A001" key="key1" />
<core:Item id="idName3" text="A002" key="key2" />
<core:Item id="idName4" text="A003" key="key3" />
</MultiComboBox>
我也为jsbin中的控制器做了类似的工作示例,作为不同的方法。
var mData = {
items:[
{key:"0",name:"A000"},
{key:"1",name:"A001"},
{key:"2",name:"A002"},
{key:"3",name:"A003"}
]
};
var oModel = new sap.ui.model.json.JSONModel(mData); //set data here
sap.ui.getCore().setModel(oModel, "ComboBoxData");
var oItemTemplate = new sap.ui.core.Item({
key : "{key}",
text : "{name}"
});
var mcb = new sap.m.MultiComboBox({
id : "mcb",
items : {
path : "/items",
template : oItemTemplate,
}
});
mcb.setModel(oModel);
//here you can select pre chosen values, for example [0,1] first two names are chosen
mcb.setSelectedKeys([0,1]);
mcb.placeAt('content');