之前使用自定根节点时,展开父节点会自动调用load方法,导致无限循环目录,代码如下:
showTreeData是本地数据:
showTreeData = [
{
id:0,
text:'123',
leaf:true
},
{
id:1,
text:'234',
children:[{
id:2,
text:'234-1',
leaf:true
}],
expanded:false
}
];
var ststoredata = Ext.encode(showTreeData); var ststore = Ext.create('Ext.data.TreeStore', { model : 'showTree', autoLoad : false, clearOnLoad:true, clearRemovedOnLoad:true, proxy: { type: 'ajax', url: '../FileMng.php?xOper=showtree&datalist='+ ststoredata,//'../FileMng.php?xOper=test&start=0&limit=1000&dir=E:'+VSC_AppRootPath,'treegrid.json' reader: { type: 'json' root: 'rs', totalProperty: 'count' } }
else if ( $xOper == "showtree") { //获取文件列表 //设初值datalist $restr = "{count:0}"; $datalist = json_decode($_GET["datalist"]); $count = $_GET["count"]; $array = array( "count" => $count, //总记录数 "rs" => $datalist //记录集 ); $restr = json_encode ($array); $count = 0; print $restr; }
修改后代码:
showTreeData = [ { id:0, text:'123', leaf:true }, { id:1, text:'234', children:[{ id:2, text:'234-1', leaf:true }], expanded:false } ]; var ststoredata = Ext.encode(showTreeData); var ststore = Ext.create('Ext.data.TreeStore', { model : 'showTree', autoLoad : false, clearOnLoad:true, clearRemovedOnLoad:true, proxy: { type: 'ajax', url: '../FileMng.php?xOper=showtree&datalist='+ ststoredata,//'../FileMng.php?xOper=test&start=0&limit=1000&dir=E:'+VSC_AppRootPath,'treegrid.json' reader: { type: 'json' // root: 'rs', //不使用自定义根节点 // totalProperty: 'count' } }
else if ( $xOper == "showtree") { //获取文件列表 //设初值datalist $restr = "{count:0}"; $datalist = json_decode($_GET["datalist"]); $count = $_GET["count"]; $array = array( "count" => $count, //总记录数 "rs" => $datalist //记录集 ); $restr = json_encode ($datalist);//不使用array,直接使用datalist返回 // $count = 0; print $restr; }