easyui-combobox 动态添加选项option

时间:2022-10-27 06:24:45

根据后台数据添加:

$("#themecombo").combobox({    
url:'<%=basePath%>analysis/getactivit.action',
valueField:'id',
textField:'title',
editable:false
});

然后想在最前面添加一个空选项:

 $(document).ready(
function(){
$.ajax({
url:'<%=basePath%>analysis/getactivit.action',
type:'post',
success:function(data){
var themecombo2 =[{ 'text':'请选择','id':''}];
for(var i=0;i<data.length;i++){
themecombo2.push({"text":data[i].title,"id":data[i].id});
}
$("#themecombo").combobox("loadData", themecombo2);
}
});
});

<td class="label" id="lthemecombo">主题: </td>
<td class="content" id="lthemecomboi">
<input id="themecombo" class="easyui-combobox" name="prefecture" style="width:160px;" data-options="editable:false,valueField:'id', textField:'text'" />
</td>