2012-08-10 53 views
0

我的树与treestore最初被加载,但请求的子节点失败。ExtJs - 如何使用动态参数加载TreeStore

在请求孩子时,传输参数localpath,该参数定义了子数据所在的路径。

初始化请求:localpath=/ - >得到所有的孩子在/

儿童要求:localpath=/subfolder1 - >得到所有的孩子在/subfolder1

我附上两张截图显示初始加载和显示文件夹时,点击。

Folders initially loaded

Folders clicked but no children

BTW:哪里有箭头我的树不见了?

的Json:我的树商店收到这样的JSON数据:

{ 
    "value": { 
     "name": "", 
     "path": "/", 
     "leaf": false, 
     "type": "folder", 
     "children": [ 
     { 
      "name": "subfolder1", 
      "path": "/subfolder1", 
      "leaf": false, 
      "type": "folder", 
      "children": [] 
     }, 
     { 
      "name": "subfolder2", 
      "path": "/subfolder2", 
      "leaf": false, 
      "type": "folder", 
      "children": [] 
     }, 
     { 
      "name": "testreports", 
      "path": "/testreports", 
      "leaf": false, 
      "type": "folder", 
      "children": [] 
     } 
     ] 
    } 
} 

商店:树店看起来是这样的:

var oTreeStore = Ext.create('X.module.store.store.Tree', { 
    model : 'X.module.store.model.TreeNode', 
    api  : this.httpApi, 
    module : "store", 
    func  : "getchildren", 
    scope : "user" 
}); 

TreePanel中创作:

var oTreePanel = Ext.create('X.module.store.view.TreePanel', { 
    store  : oTreeStore 
}); 

TreePanel中定义:

constructor: function(oConfig) { 

    var self = this; 
    //creating a proxy, which can communicate with HTTP-API 
    //and is able to parse it's json-tree format 

    var oProxy = Ext.create('X.lib.httpapiclient.Proxy', { 
     api  : oConfig.api, 
     module : oConfig.module, 
     func : oConfig.func, 
     params : { 
      scope  : oConfig.scope 
     }, 
     reader : { 
      type: 'json', 
      root: function(o) { return o.value? o.value.children : o.children; } 
     }, 
     delay : oConfig.delay || 100, 
     success : oConfig.success || function() {}, 
     progress: oConfig.progress || function() {}, 
     error : oConfig.error || function() {} 
    }); 

    oConfig.nodeParam = 'localpath'; 
    oConfig.proxy = oProxy; 

    self.callParent(arguments); 

    //the HTTP-API requires the ID of the root-node to be empty 
    self.on('beforeload', function(s, o) { 
     if(o.params.localpath === 'root') o.params.localpath = '/'; 
    }); 


    } 

型号:模型...

Ext.define('X.module.store.model.TreeNode', { 
     extend: 'Ext.data.Model', 
     fields: [ 
     { name: 'name',   type: 'string' }, 
     { name: 'path',   type: 'string' }, 
     { name: 'type',   type: 'string' } 
     ] 
    }); 

回答

0

的解决方案是提供在children物业孩子。在我的情况下,我提供这样的空儿童children: []。所以没有什么可显示的。