top
Loading...
jQuery EasyUI 樹形菜單 – 創建異步樹形菜單

jQuery EasyUI 樹形菜單 - 創建異步樹形菜單

為了創建異步的樹形菜單(Tree),每一個樹節點必須要有一個 'id' 屬性,這個將提交回服務器去檢索子節點數據。

創建樹形菜單(Tree)

    <ul id="tt" class="easyui-tree"
            url="tree2_getdata.asp">
    </ul>

服務器端代碼

    $id = isset($_POST['id']) ? intval($_POST['id']) : 0;
    include 'conn.asp';
    $result = array();
    $rs = mysql_query("select * from nodes where parentId=$id");
    while($row = mysql_fetch_array($rs)){
        $node = array();
        $node['id'] = $row['id'];
        $node['text'] = $row['name'];
        $node['state'] = has_child($row['id']) ? 'closed' : 'open';
        array_push($result,$node);
    }
    echo json_encode($result);
    function has_child($id){
        $rs = mysql_query("select count(*) from nodes where parentId=$id");
        $row = mysql_fetch_array($rs);
        return $row[0] > 0 ? true : false;
    }
北斗有巢氏 有巢氏北斗