1. 程式人生 > >easyui combotree預設全部選中

easyui combotree預設全部選中

$('#puruserid').combotree({
			url : url,
			cascadeCheck : false,
			multiple : true,
			panelHeight : 180,
			required:true,
			formatter : function(node) {
				node.text = node.name;
				return node.name;
			},
			 onLoadSuccess:function(node,data){ 
				 if(data.length>0){
					 var arr = [];
					 for(var j = 0,len = data.length; j < len; j++){
	             		arr.push(data[j].id);
					}
					 $("#puruserid").combotree('setValues',arr);
				 }
			 }
		});

關鍵程式碼:

 $("#puruserid").combotree('setValues',arr);

如果只是想選中第一條資料,程式碼如下:

$('#puruserid').combotree({
			url : url,
			cascadeCheck : false,
			multiple : true,
			panelHeight : 180,
			required:true,
			formatter : function(node) {
				node.text = node.name;
				return node.name;
			},
			 onLoadSuccess:function(node,data){ 
				 $("#puruserid").combotree('setValues',data[0].id);
			 }
		});