日期:2014-05-16  浏览次数:20319 次

EXTJS4,treepanel,书上例子,rootVisible:false就不显示任何东西,反之则能显示点东西
本帖最后由 yufulou 于 2013-01-28 14:35:28 编辑
《ExtJS WEB应用程序开发指南》里的分级加载树节点的例子,原例子写的rootVisible:false却显示不出来任何东西,反之才能显示,为什么?
前台:
Ext.define('OrgInfo', {
       extend: 'Ext.data.Model',
       fields: ['orgId', 'name', 'count']
});

var myStore = new Ext.data.TreeStore({
model: 'OrgInfo',
nodeParam: 'orgId', 
proxy: {
type:'ajax',
url:'/policy/policy_block/test_tree',
reader:'json'
},
autoLoad:true,
root:{
name: '根',
id:'-1'
}
});

Ext.create('Ext.tree.Panel', {
title: '异步加载树节点',
renderTo:Ext.getBody(),
width:250, 
height:150,
store: myStore,
rootVisible:true,
columns:[{
xtype: 'treecolumn',
text: '公司名称',
dataIndex: 'name',
width: 150,
sortable: true
},{
text: '员工人数',
dataIndex: 'count',
flex:1,
sortable:true
}]
});

后台,用php写的,返回值和例子里是一样的:
$org_id = $this->_get('id');
$result = "";
if(-1 == $org_id){
$result = "[{name:'总公司', count: 100, id:100}]";
}else if(100 == $org_id){
$result = "[{name: '分公司一', count:20, id:110, leaf:true}, {name:'分公司二', count:80, id:120}]";
}else if(120 == $org_id){
$result = "[{name:'部门一', count:30, id:121, leaf:true},{name:'部门二', count:50, id:122, leaf:true}]";
}
if(ob_get_length())ob_clean();
header("Content-Type: text/json");
echo $result;

------解决方案--------------------
rootVisible是不显示根节点,楼主仔细检查一下自己的代码
------解决方案--------------------
引用:
rootVisible是不显示根节点,楼主仔细检查一下自己的代码


您没看懂我的意思,刚才已经在另一个例子里找到解决办法了,root需要增加一个expanded:true的属性,然后rootVisible:false以后,树才能显示内容,否则就是空白一片