2012-08-10 41 views
2

我想通過extjs4.1在braches位於不同的URL上的情況下在一個MVC應用程序中實現延遲加載樹分支。我已經有相當多的方法,並且碰到相當多的牆壁,現在它不會分支。extjs 4.1 treestore延遲加載:q是,是否分支?

這裏是我失敗:

Ext.define('OI.view.tree.Tree' ,{ 
    extend: 'Ext.tree.Panel', 
    alias : 'widget.treepanel', 
    store: 'TreeStore', 
    collapsible: true, 
    rootVisible: false, 

    viewConfig: { 
     plugins: [{ 
      ptype: 'treeviewdragdrop' 
     }] 
    }, 
    height: 350, 
    width: 400, 
    title: 'Directory Listing', 

    initComponent: function() { 
     this.store = Ext.data.StoreManager.lookup(this.store); 
     this.store.getProxy().url = 'data/level1.json'; // <-- init loading 
     this.store.load(); 
     this.callParent(arguments); 
    }, 

    listeners: { 
     itemclick: function(view, record) { 

      console.info('ID: '+record.get('id')); 
      console.info('TEXT: '+record.get('text')); 
      console.info('PrimType: '+record.get('primaryType')); 
      console.info(record.fields.getCount()); 
      console.info('JCRPATH: '+record.get('jcrPath')); 

      var newBranchStore = Ext.create('Ext.data.TreeStore', { 
       model: 'OI.model.Branch', 
       autoLoad: true, 
       proxy: { 
        type: 'ajax', 
        reader: { 
         url: 'data/'+ record.get('jcrPath') +'/level1.json', //<-- load json at the level of the url path returned by the model 
         type: 'json' 
        } 
       }, 
       folderSort: false 
      }); 

      newBranchStore.load({url: 'data/'+ record.get('jcrPath') +'/level1.json', 
       callback: function(){ 
        console.log('loaded'); 
        var mynode = newBranchStore.getNodeById('content_mytest'); 
        console.info(mynode.get('id')); 
        this.store.getNodeById(record.get('id')).appendChild(mynode).expand(); // <-- this does not work 
       }, 
       scope: this 
      }); 
     } 
    } 
}); 

第一個層次是正確加載,但是當我觸發節點上的點擊,我得到正確的JSON從服務器返回,在這種情況下,靜態json文件進行調試,我嘗試靜態獲取節點並將其附加到已被單擊的節點上。但它從未被注入。

我最終想要實現的是我可以將json文件返回的所有子節點附加到已被單擊的節點。

此外,我有點困惑treestores ... 我是否正確,當我說每棵樹只能有一個樹存儲,對不對?所以我需要將新節點附加到原始樹庫...我有點困惑,可能需要我可以獲得的所有指針。

回答

3

你的方式過於複雜這一點,使用這種方法,而不是(基本上只是換出你的店的網址,它加載正確的URL前):

Ext.define('OI.view.tree.Tree' ,{ 
    extend: 'Ext.tree.Panel', 
    alias : 'widget.treepanel', 
    store: 'TreeStore', 
    collapsible: true, 
    rootVisible: false, 

    viewConfig: { 
     plugins: [{ 
      ptype: 'treeviewdragdrop' 
     }] 
    }, 
    height: 350, 
    width: 400, 
    title: 'Directory Listing', 

    initComponent: function() { 
     this.store = Ext.data.StoreManager.lookup(this.store); 
     this.store.getProxy().url = 'data/level1.json'; // <-- init loading 
     this.store.load(); 
     this.callParent(arguments); 
    }, 

    listeners: { 

     beforeload: function(store, operation) { 
      store.getProxy().url = 'data/'+ operation.node.get('jcrPath') +'/level1.json'; 
     } 
    } 
}); 
+0

非常感謝......你需要改變它到beforeload:function(store,operation){爲了正常工作... – mahatmanich 2012-08-14 07:29:52