本文主要是介绍Asp.net MVC中EasyUI Commobox和Combotree绑定和获取数据,希望对大家解决编程问题提供一定的参考价值,需要的开发者们随着小编来一起学习吧!
=============================combobox绑定和获取数据====================================
1、获取选中的值
$('#comboboxlist').combobox('getValue'); //单选时
$('#comboboxlist').combobox('getValues'); //多选时
2、赋值
$('#comboboxlist').combobox('setValue', '北京'); $('#cbbStatus').combobox({url: '@Url.Action("GetHouseStatue", "HouseInfo")',valueField: 'Value',textField: 'Text',onSelect: function (res) {console.log(res);}
});<input id="cbbStatus" class="easyui-combobox" data-options="prompt:' - 选择状态 - '" editable="false" />#region 获取房源信息状态
public ActionResult GetHouseStatue()
{//房源状态0待审核1审核通过2审核不通过3上架4下架List<ComboboxData> models = new List<ComboboxData>();models.Add(new ComboboxData() { Text = "待审核", Value = "0" });models.Add(new ComboboxData() { Text = "审核通过", Value = "1" });models.Add(new ComboboxData() { Text = "审核不通过", Value = "2" });models.Add(new ComboboxData() { Text = "上架", Value = "3" });models.Add(new ComboboxData() { Text = "下架", Value = "4" });return Json(models, JsonRequestBehavior.AllowGet);
}
#endregion==========================================combotree绑定和获取数据=================================$(function () {$("#cbt").combotree({width: 175,url: '@Url.Action("GetComboTreeJson", "Test")',valueField: 'id',textField: 'text',editable: false});$("#btnSubmit").click(function () {//获取当前combotree的tree对象var tree = $('#cbt').combotree('tree');//获取当前选中的节点var data = tree.tree('getSelected');//查看当前选中节点的idconsole.log("选择的数据", data.id, data.text);});
});/// <summary>
/// 异步加载无限Tree
/// </summary>
/// <returns></returns>
[HttpPost]
public string GetComboTreeJson()
{//easyui 会每展开一个节点,往后端传一个idstring parentNodeId = RequestHelper.GetString("id") ?? null;if (string.IsNullOrEmpty(parentNodeId)){parentNodeId = "0";}List<TreeModule> tree = GetSubNodes(parentNodeId, "module_fatherid","module_id", "module_name");string JsonStr = JsonConvert.SerializeObject(tree);return JsonStr;
}/// <summary>
/// 获取ComboTree方法
/// </summary>
/// <param name="parentNodeId">父节点数据</param>
/// <param name="fatherColumn">父节点字段名</param>
/// <param name="idColumn">ID字段名</param>
/// <param name="textColumn">TEXT字段名</param>
/// <returns></returns>
private List<TreeModule> GetSubNodes(string parentNodeId, string fatherColumn,string idColumn,string textColumn)
{DataTable dt = CreateDT();List<TreeModule> Tree = new List<TreeModule>();TreeModule TM = null;if (dt != null && dt.Rows.Count > 0){DataRow[] rows = dt.Select(string.Format("{0} = '{1}'", fatherColumn, parentNodeId));foreach (DataRow item in rows){string id = item[idColumn].ToString();string text = item[textColumn].ToString();TM = new TreeModule();DataRow[] IsNulRows = dt.Select(string.Format("{0} = '{1}'", fatherColumn, id));if (IsNulRows.Length > 0){//这个很关键,此节点为closed状态,才可以展开,才能往后台传你点击的id //看到Combotree的异步加载Demo,发现treegrid_data.json中 state="closed" 属性能把点击展开的节点Id传到后台中TM.state = "closed";}TM.id = id;TM.text = text;Tree.Add(TM);}}return Tree;
}
@{Layout = null;
}<!DOCTYPE html><html>
<head><meta name="viewport" content="width=device-width" /><title>HouseInfo信息列表</title><link type="text/css" rel="stylesheet" href="/css/default.css" /><!--easyui--><link rel="stylesheet" type="text/css" href="/JS/jquery-easyui-1.5.5.5/themes/default/easyui.css" /><link rel="stylesheet" type="text/css" href="/JS/jquery-easyui-1.5.5.5/themes/default/tree.css" /><link rel="stylesheet" type="text/css" href="/JS/jquery-easyui-1.5.5.5/themes/icon.css" />
这篇关于Asp.net MVC中EasyUI Commobox和Combotree绑定和获取数据的文章就介绍到这儿,希望我们推荐的文章对编程师们有所帮助!