=============================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');
//查看当前选中节点的id
console.log("选择的数据", data.id, data.text);
});
});
/// <summary>
/// 异步加载无限Tree
/// </summary>
/// <returns></returns>
[HttpPost]
public string GetComboTreeJson()
{
//easyui 会每展开一个节点,往后端传一个id
string 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" />