easui tree载入时自动展开无子节点的节点

时间:2021-12-12 23:25:38

利用loadFilter对后台返回的原始数据进行过滤处理,将数据中的state字段修改相应的值,若无子节点,则改成open,若有子节点,则改成closed。

由于一个node属性只有下面几项内容,因此利用checked字段,于是有了下面的sql查询语句,

  • id: An identity value bind to the node.
  • text: Text to be showed.
  • iconCls: The css class to display icon.
  • checked: Whether the node is checked.
  • state: The node state, 'open' or 'closed'.
  • attributes: Custom attributes bind to the node.
  • target: Target DOM object.
string sql = "SELECT     id,  text, 是否有子节点 as checked FROM table where  父节点 =@father";

前台javascript语句:

$(function () {
$('#tree').tree({
animate: true,
url: 'handler/PostDataHandler.ashx?type=9',
lines: true, loadFilter: function (data, parent) {
for (var i = 0; i < data.length; i++) {
if (data[i].checked == "False") {
data[i].state = "open";
}
}
return data;
}
});
})