需要引用js
留下qq,我私发
1.Html
<div class="layui-inline">
<label class="layui-form-label"><font color="red">*</font>题库</label>
<div class="layui-input-inline">
<div id="logic" class="xm-select-demo"></div>
</div>
</div>
2.JS
/*树形下拉复选框*/
var logic = xmSelect.render({
el: '#logic',
model: {
label: {
type: 'block',
block: {
showCount: 2, //最大显示数量, 0:不限制
//showIcon: false, //是否显示删除图标
}
}
},
tree: {
show: true, //父级可选
expandedKeys: true, //[100]默认展开节点的数组, 为 true 时, 展开所有节点
},
height: 250, //'auto' 高度自适应
data: []
})
$.ajax({
type: "get",
url: url,
contentType: "application/json; charset=utf-8",
async: false,//是否异步执行
success: function (t) {
if (!t) {
$.modalAlert("未获取到题库");
return;
}
t = JSON.parse(t);
logic.update({
data: t.data,
autoRow: true,
})
},
error: function (err) {
}
});
3.后台代码
//获取数据
public ActionResult GetGradeAndClass(string logicCode)
{
try
{
List<ItemDetails> newlist = new List<ItemDetails>();
return Content((new { data = newlist }).ToJson());
}
catch (Exception ex)
{
return new JsonResult() { Data = new { state = "error", message = "查询数据失败:" + ex.Message + "" } };
}
}
//数据模型
public class ItemDetails
{
public string value { get; set; }
public string name { get; set; }
public bool selected { get; set; }//设置为true 界面展示会选中
public List<ClassDetails> children { get; set; }//子树
}
public class ClassDetails
{
public string value { get; set; }
public string name { get; set; }
public bool selected { get; set; }//设置为true 界面展示会选中
public List<ClassDetails> children { get; set; }//子树
}