<input id="line" name="line" style="max-width:120px;" class="easyui-combobox" data-options="url:'/Common/selectList?selectTable=line&headTitle=true',valueField: 'Value',textField: 'Text',value:0"/>
<input id="proc" name="proc" style="max-width:120px;" class="easyui-combobox" data-options="url:'/Common/selectList?selectTable=proc&headTitle=true',valueField: 'Value',textField: 'Text',value:0" />
<input id="maker" name="maker" style="max-width:120px;" class="easyui-combobox" data-options="url:'/Common/selectList?selectTable=maker&headTitle=true',valueField: 'Value',textField: 'Text',value:0" />
ASP.NET MVC 后台:
[HttpPost] public ActionResult selectList(string selectTable = "", bool headTitle = false, string value = "") { value = value.Length == 0 ? "0" : value; switch (selectTable) { case "line": List<line> lineList = Business.Produce.Instance.LineEnabledList(); if (headTitle) lineList.Insert(0, new line { line_id = 0, name = "选择产线" }); Common.Http.ResponseJson(lineList.Select(m => new SelectListItem { Text = m.name, Value = m.line_id.ToString() })); break; case "proc": List<proc> procList = Business.Produce.Instance.GetProcByLineId(Convert.ToInt32(value)); if (headTitle) procList.Insert(0, new proc { proc_id = 0, name = "选择工艺" }); Common.Http.ResponseJson(procList.Select(m => new SelectListItem { Text = m.name, Value = m.proc_id.ToString() })); break; case "maker": List<maker> makerList = Business.Device.Instance.MakerList(); if (headTitle) makerList.Insert(0, new maker { maker_id = 0, name = "选择厂家" }); Common.Http.ResponseJson(makerList.Select(m => new SelectListItem { Text = m.name, Value = m.maker_id.ToString() })); break; } return null; }
调用selectList方法输出的JSON为:
[{"Disabled":false,"Group":null,"Selected":false,"Text":"测试产线1","Value":"1"}]
特别注意的是: 这条JSON数据,不能出现 单引号, EasyUI-commbobox 插件不支持单引号 ,如[{‘Disabled':false,'Group':null,'Selected':false,'Text':'测试产线1','Value':'1'}],则下拉列表加载不到数据,
所以,后台JSON 最好不要拼接,调用 JsonConvert.SerializeObject(obj, Formatting.None)进行序列化。