I use SelectItem with DataSource, it works well. When I set the propety multiple to ture like below:
{
ID:“component1”,
title:“Category”,
displayField:“name”,
editorType:“select”,
valueField:“id”,
multiple:true,
optionDataSource:ds
}
it doesn’t work! And if I provide a valueMap to the SelectItem
{
ID:“component1”,
title:“Category”,
displayField:“name”,
editorType:“select”,
valueField:“id”,
multiple:true,
valueMap:{
“abc”:“1”,
“def”:“2”
}
}
it works again. It seems that multiple SelectItem can not work well with Datasource, but I think this is a common requirement.
How can I solve this problem? I need help.
Hi seal_hu,
You’re right that this is not currently supported.
We have support for a databinding-capable multiple select component planned but it is not yet available.
For now the suggested approach is to retrieve a your options from the server via an explicit call to dataSource.fetchData(…) and, as part of the callback passed to that method, create a valueMap and apply it to your multiple select item - something like this:
// create a valueMap based on a mapping between
// 'dataField' and 'displayField' on some dataSource
myDataSource.fetchData(null,
function (dsResponse, data) {
var map = {};
for (var i = 0; i < data.length; i++) {
map[data[i].dataField] = data[i].displayField;
}
var item = myForm.getItem("myMultiSelect");
item.setValueMap(map);
}
)