shaomin306963591
shaomin306963591
2012-10-28 14:34

ExtJs 4 Tree 展示问题

已采纳

最近在学习ExtJs4,遇到一个问题,大家帮忙分析一下

 

 

JS代码如下:

 

Ext.require([
    'Ext.tree.*',
    'Ext.data.*',
    'Ext.tip.*'
]);

Ext.onReady(function() {

var treeStore = new Ext.data.TreeStore({
    proxy: {
        type: 'ajax',
        url: ctx + '/common/tree'
    },
    root: {
        text: 'Ext JS',
        id: 'src',
        expanded: true
    },
    sorters: [{
        property: 'leaf',
        direction: 'ASC'
    }, {
        property: 'fileName',
        direction: 'ASC'
    }]
});

var treePanel = new Ext.tree.TreePanel({
    region : 'west',
    title : '<center>系统菜单</center>',
    split : true,
    width : 200,
    root : treeStore
});

var topPanel = new Ext.Panel({
    region : 'north',
    frame : false,
    height : 28
});

var mainPanel = new Ext.TabPanel({
    layout : 'fit',
    activeTab : 0,
    region : 'center',
    frame : false
});

    Ext.QuickTips.init();
    var mvp = new Ext.Viewport({
        layout : 'border',
        items : [ treePanel, topPanel, mainPanel ]
    });
});

 

后台返回数据如下:

 

 

[
    {
        "id": "1001",
        "text": "admin",
        "parentId": "-",
        "leaf": false,
        "iconCls": "1001-tree",
        "cls": "folder",
        "children": [
            {
                "id": "100101",
                "cls": "file",
                "url": "/common/admin",
                "name": "admin",
                "leaf": true,
                "text": "admin",
                "parentId": "1001"
            }
        ]
    },
    {
        "id": "1002",
        "text": "user",
        "parentId": "-",
        "leaf": false,
        "iconCls": "1002-tree",
        "cls": "folder",
        "children": [
            {
                "id": "100201",
                "cls": "file",
                "url": "/common/common",
                "name": "user",
                "leaf": true,
                "text": "user",
                "parentId": "1002"
            }
        ]
    }
]

页面就是显示不了树结构,不知为什么??

页面显示如图:


 

  • 点赞
  • 写回答
  • 关注问题
  • 收藏
  • 复制链接分享
  • 邀请回答

4条回答

  • macrao macrao 9年前

    这里你的TreePanel 里面啊是要定义store,而不是root:
    [code="js"]
    var treePanel = new Ext.tree.TreePanel({

    region : 'west',

    title : '

    系统菜单',

    split : true,

    width : 200,

    store : treeStore

    });

    [/code]
    点赞 6 评论 复制链接分享
  • j469799470 j469799470 9年前

    1楼的答案是对的 data:..//数据源

    点赞 评论 复制链接分享
  • maoyxiong maoyxiong 9年前

    因为你的parentId 为“-”,必须和根节点的id相同,也就是和id: 'src' 这个id相同

    点赞 评论 复制链接分享
  • iteye_5246 iteye_5246 9年前

    哥们json格式不是tree需要的
    所有不展示
    json格式如下:

    {id:root,children[]{}}

    { "id":"root", "iconCls":"icon-docs", "text":"根节点", "singleClickExpand":true, "expanded":true, "leaf":false, "children":[{ "id":"id1", "iconCls":"icon-pkg", "text":"子节点一", "qtip":"asdk",//需要使用 Ext.QuickTips.init();//开启提示功能 "singleClickExpand":true, "expanded":true, "leaf":true },{ "id":"child2", "iconCls":"icon-pkg", "text":"子节点二", "singleClickExpand":true,//单击节点是否展开 "expanded":true, "leaf":false, "children":[{ "id":"child21", "iconCls":"icon-pkg", "text":"子节点三", "singleClickExpand":true,//单击节点是否展开 "expanded":true, "leaf":true }] }]};

    点赞 评论 复制链接分享

相关推荐