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