html:
<div class="add_box add_typename">
<span class="id_name"><i>*</i>范围值</span>
<select id="cmdRangeValue_edit" class="easyui-combotree" name="dept" data-options="required:true,multiple:true,checkbox:true," style="width: 200px;"></select>
</div>
jQuery:
$.get("/Rights/JobViewRange/GetJobViewRangeByID", { JobViewRangeID: id }, function (data) {
$.getJSON("/Rights/JobViewRange/GetRangeValueJson",
{ RangeType: data.RangeType },
function (json) {
$("#cmdRangeValue_edit").combotree({
data: json,//获取要显示的json数据
valueField: 'id',
textField: 'text',
});
$("#cmdRangeValue_edit").combotree("setValues", data.RangeValue);//注意,是:setValues
});
});
MVC-Controller(注1:一定要先生成combotree的所有节点):
//获取已选中节点的值(多个值用 , 逗号间隔)
public ActionResult GetJobViewRangeByID(int JobViewRangeID)
{
var jobQuery = new JobViewRangeQuery() { JobViewRangeID = JobViewRangeID };
var job = JobViewRangeService.GetJobViewRange(jobQuery).FirstOrDefault();
return Json(job, JsonRequestBehavior.AllowGet);
}
//生成combotree所有节点的json
public ActionResult GetRangeValueJson(string RangeType)
{
if (string.IsNullOrEmpty(RangeType) || string.IsNullOrWhiteSpace(RangeType)) return Content("");
string json = JobViewRangeService.GetRangeValueJson(RangeType);
return Content(json);
}
注2:生成combotree所有节点后,再将值的集合,如:RangeValue= "2,3,4,5,8"; 的字符串传递给combotree
$("#cmdRangeValue_edit").combotree("setValues", data.RangeValue);