[英]How can I set Selected items in a sapui5 MultiComboBox?
I have the following json data: 我有以下json数据:
{
"medios":[
{
"Medio":"Cheque",
"Key":"5"
},
{
"Medio":"Transferencia Bancaria",
"Key":"6"
}
]
}
And I bind this data using a json model: 我使用json模型绑定此数据:
var oModelTest = new sap.ui.model.json.JSONModel();
var MediosPagoPromesa = [];
var MedioObj = {
Medio: proMedioPagoCP, //a variable I fill inside a loop
Key: i.toString() //because it is inside a loop
}
MediosPagoPromesa.push(MedioObj);
oModelTest.setData({
'medios': MediosPagoPromesa
});
sap.ui.getCore().setModel(oModelTest, "Pagos");
into a MultiComboBox: 放入MultiComboBox:
var test = sap.ui.getCore().getModel("Pagos");
var oMultiSelect = new sap.m.MultiComboBox({
items: {
path: "/medios",
template: new sap.ui.core.ListItem({
key: '{Key}',
text: '{Medio}'
}),
templateShareable: true
},
selectedKeys: ?, //here is my problem
});
oMultiSelect.setModel(test);
What I don't know, is how can I set as selected Items, all the items I am binding in the MultiComboBox, So they can be automatically displayed as selected even from the first time, any idea idea how can I achieve this? 我不知道的是,如何将MultiComboBox中绑定的所有项目设置为选定项目,所以即使是从头开始,它们也可以自动显示为选定状态,我知道如何实现?
add a new array of the selected element filed in the the loop 在循环中添加所选元素的新数组
var oModelTest = new sap.ui.model.json.JSONModel();
var MediosPagoPromesa = [];
var selected = [];
var MedioObj = {
Medio: proMedioPagoCP, //I variable I fill inside a loop
Key: i.toString() //because it is inside a loop
}
selected.push(i.toString); //inside the loop
MediosPagoPromesa.push(MedioObj);
oModelTest.setData({
'medios': MediosPagoPromesa,
'selected' : selected
});
sap.ui.getCore().setModel(oModelTest, "Pagos");
In MultiComBox use bindProperty to bind the selectedKeys property 在MultiComBox中,使用bindProperty绑定selectedKeys属性
var test = sap.ui.getCore().getModel("Pagos");
var oMultiSelect = new sap.m.MultiComboBox({
items: {
path: "/medios",
template: new sap.ui.core.ListItem({
key: '{Key}',
text: '{Medio}'
}),
templateShareable: true
},
});
oMultiSelect.bindProperty("selectedKeys", "/selected");
oMultiSelect.setModel(test);
Here is jsbin with clear example : https://jsbin.com/murural/1/edit?html,js,output 这是带有清晰示例的jsbin: https ://jsbin.com/murural/1/edit?html,js,output
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.