easyui-combobox url绑定后台json数据问题
2017-04-21 17:32
295 查看
<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 后台:
调用selectList方法输出的JSON为:
<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)进行序列化。
相关文章推荐
- WEB_EasyUI中comboBox远程绑定json数据引起的访问跨域问题
- easyUI下拉框控件easyui-combobox使用后台json文件填充数据失败的问题
- [置顶] easyui datagrid combobox通过url获取json数据的下拉框
- 使用easyui-combobox的data属性加载定义好在*.js文件中的JSON数据的问题
- easyUI combobox json 从后台取数据显示
- easyui-combobox绑定json数据
- easyui-combobox 传递参数到后台获取json来绑定选项
- easyUI-combobox 后台导入Json数据的方法
- toolstripcombobox 绑定数据问题
- easyui-处理含html内容的json数据时不能转换的问题
- extjs JsonStore加载数据,Combobox只显示最后一项值问题
- javascript中创建对象,并序列化为json,通过$.ajax的提交json数据到后台方法,取值为null的问题
- extjs JsonStore加载数据,Combobox只显示最后一项值问题
- DataGridview中DataGridViewComboBoxColumn数据绑定的问题
- extjs JsonStore加载数据,Combobox只显示最后一项值问题
- DataGridView中comboBox数据绑定的问题
- 【ExtJS实践】之六 :Combobox从后台获取JSON格式的数据
- html中后台动态绑定数据表格存在空白单元格问题
- 关于.net winform ComboBox数据绑定显示问题
- ComboBox 绑定到数据表中一个列的问题