easui tree載入時自動展開無子節點的節點

利用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;
                }
            });
        })



發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章