1
EasyUI 1.3.3版本: 我想知道如何設置valueField(即用戶選擇某個選項後將在組合框中顯示的內容)爲組合名稱&項目名稱(例如Grp1-item1)。EasyUI:Combobox中的組合
var data = [
{group:'Group1',items:[
{value:'v11',text:'Option11'},
{value:'v12',text:'Option12'},
{value:'v13',text:'Option13'},
{value:'v14',text:'Option14'}
]},
{group:'Group2',items:[
{value:'v21',text:'Option21'},
{value:'v22',text:'Option22'},
{value:'v23',text:'Option23'},
{value:'v24',text:'Option24'}
]}
];
function loadFilter(data){
var dd = [];
for(var i=0; i<data.length; i++){
var group = data[i].group;
dd.push({
group:group,
text:group
});
dd = dd.concat(data[i].items);
}
return dd;
}
function onLoadSuccess(){
var groupItems = $(this).combobox('panel').find('div.combobox-item:has(span.combobox-group-text)');
groupItems.removeClass('combobox-item');
}
function formatter(row){
if (row.group){
return '<span class="combobox-group-text" style="font-weight:bold">'+row.group+'</span>';
} else {
return '<span style="padding-left:10px">'+row.text+'</span>';
}
}
$(function(){
$('#cc').combobox({
data:data,
loadFilter:loadFilter,
formatter:formatter,
onLoadSuccess:onLoadSuccess
});
});