Extjs Tree未在父节点上显示文本也无法加载子节点

时间:2013-01-23 06:57:17

标签: php mysql extjs extjs4

我正在使用php / mysql数据加载树面板。 但是当我点击加载树子节点时,它也没有显示父节点的名称。它获取记录并在控制台中显示json响应,但无法在树中加载子节点。

父节点的Json响应:

[{"0":"1","id":"1","1":"Settings","name":"Settings","leaf":false,"cls":"folder"},{"0":"2","id":"2","1":"Data","name":"Data","leaf":false,"cls":"folder"},{"0":"3","id":"3","1":"Reports","name":"Reports","leaf":false,"cls":"folder"},{"0":"4","id":"4","1":"Campaigns","name":"Campaigns","leaf":false,"cls":"folder"}]

子节点的Json响应

[{"0":"1","id":"1","1":"Home","text":"Home","leaf":false,"cls":"folder"},{"0":"2","id":"2","1":"Log out","text":"Log out","leaf":false,"cls":"folder"},{"0":"47","id":"47","1":"Campaign Reports","text":"Campaign Reports","leaf":false,"cls":"folder"},{"0":"49","id":"49","1":"Supplier Stats","text":"Supplier Stats","leaf":false,"cls":"folder"},{"0":"50","id":"50","1":"Label Piechart","text":"Label Piechart","leaf":false,"cls":"folder"},{"0":"51","id":"51","1":"Country Piechart","text":"Country Piechart","leaf":false,"cls":"folder"},{"0":"52","id":"52","1":"Supplier Piechart","text":"Supplier Piechart","leaf":false,"cls":"folder"},{"0":"53","id":"53","1":"Over All piechart","text":"Over All piechart","leaf":false,"cls":"folder"}]

js文件:

var store = Ext.create('Ext.data.TreeStore', {
    autoLoad : true,
    root: {
        id : 'root_node',
        expanded: true
    },
    proxy: {
        type: 'ajax',
        url: 'tree-dataa.php'
    }
});

// Go ahead and create the TreePanel now so that we can use it below
 var treePanel = Ext.create('Ext.tree.Panel', {
    id: 'tree-panel',
    region:'north',
    split: true,
    height: 360,
    minSize: 150,
    rootVisible: true,
    autoScroll: true,
    store: store
    });

Php文件:tree-dataa.php

<?php
    mysql_connect("localhost", "root", "");
    mysql_select_db("newslettercms_db");        
    $data = array();
    $q = "";
    $department = $_REQUEST['node'];

        if ($department == 'root_node') {
            $q =mysql_query("SELECT `id`,`name` FROM `cms_roles`");
        }else {
            $qq =mysql_query("SELECT right_ids FROM `cms_roles` WHERE id = '". $department ."'");
            while($ar=mysql_fetch_array($qq))
                {   
                    $q = mysql_query("SELECT `id`,`text` FROM cms_rights where id IN (".$ar['right_ids'].")");                                      
                }    
        }
        while($arr=mysql_fetch_array($q))
        {
            if ($department != 'myCompany') {
                $arr['leaf']     = false;
                $arr['cls']     = 'folder';

            }
            else {
                //$arr['leaf'] = true;
                //$arr['cls'] = 'file';
            }


            $data[] = $arr;
        }
        echo json_encode($data);
?>

0 个答案:

没有答案