1. #1
    Sencha User
    Join Date
    Feb 2008
    Posts
    31
    Vote Rating
    0
    salvo is on a distinguished road

      0  

    Default Unanswered: How to get the owner tree of a node?

    Unanswered: How to get the owner tree of a node?


    In ExtJS 4 how to get the reference of owner tree for a particular node?

    node.getOwnerTree() method was handy in ExtJS 3 but unfortunately it's gone - Ext.data.NodeInterface does not provides reference to parent component.

    Any idea to get around this in ExtJS 4 ?

  2. #2
    Sencha Premium Member
    Join Date
    Apr 2011
    Posts
    101
    Vote Rating
    3
    Answers
    8
    sskow200 is on a distinguished road

      0  

    Default


    A couple of ways. Would need to see how/where you're trying to get access to find the best solution. Could be as simple as Ext.getCmp('mytreepanel'), but if you're trying not to access it globally then you could use a number of other ways.

  3. #3
    Sencha User
    Join Date
    Feb 2008
    Posts
    31
    Vote Rating
    0
    salvo is on a distinguished road

      0  

    Default


    sskow200

    This is part of a large v3 -> v4 migration project so exposing a test case is not easy.

    I'm using multiple instances of a tree component with different data models. Tree id is not set by config but by the framework during instantiation.

    I need to access tree in some methods extending data model where this is the current node.

    On store load I could possibly repaint each node with a ownerTreeId property to access it later with Ext.getCmp(this.data.ownerTreeId) but this looks a bit odd to me compared to the handiness provided by ExtJS 3 's getOwnerTree().

    Could you shortly expose some of the "number of other ways"? Thanks.

  4. #4
    Sencha User
    Join Date
    Oct 2011
    Location
    Ukraine
    Posts
    154
    Vote Rating
    6
    Answers
    11
    Romick is on a distinguished road

      0  

    Default Some code

    Some code


    Hi

    I can say that:
    to get store
    PHP Code:
    var store tree.getStore(); 
    to get root node you can use
    PHP Code:
    var root store.getRootNode() 
    to get node when you know it's id
    PHP Code:
    var node store.getNodeById(someNodeId
    and when you need parent you can use
    PHP Code:
    var parent node.parentNode 
    Is that what you need?

  5. #5
    Sencha User
    Join Date
    Feb 2008
    Posts
    31
    Vote Rating
    0
    salvo is on a distinguished road

      0  

    Default


    Thanks for the answer Romick. Unfortunately this is not what I want to achieve.

    I know how to go from tree to node
    tree -> store -> node

    What I want is the opposite in a context where this is the actual node
    node -> tree

  6. #6
    Sencha Premium Member
    Join Date
    Apr 2011
    Posts
    101
    Vote Rating
    3
    Answers
    8
    sskow200 is on a distinguished road

      0  

    Default


    again. your best bet is to just query the dom for the tree. If you want a more generic solution, you can extend NodeInterface and add a property to the model that is the selector for the tree. Then create a method to return the instance of the tree.

  7. #7
    Sencha User
    Join Date
    Jan 2012
    Posts
    22
    Vote Rating
    0
    dee1 is on a distinguished road

      0  

    Default


    Similar V3 to V4 problem here: http://www.sencha.com/forum/showthre...rTree&p=734637

    @sskow200 I gather the node has no tree reference and we have multiple trees
    In this case, is it still possible to query the dom for the tree using the Node Id if we don't know which tree it is?

  8. #8
    Sencha User
    Join Date
    Oct 2011
    Location
    Ukraine
    Posts
    154
    Vote Rating
    6
    Answers
    11
    Romick is on a distinguished road

      0  

    Thumbs up Ok

    Ok


    Ok i understand. But can you give us a little peace of code to see it. maybe there is not neccesery that method. Just send tree reference as simple function parameter.

  9. #9
    Sencha User
    Join Date
    Jan 2012
    Posts
    22
    Vote Rating
    0
    dee1 is on a distinguished road

      0  

    Default


    @Romick following is some example code that might help

    ExtJS 3: the tree reference can be passed as a simple function parameter
    In our case we have custom html form elements that have access to the Tree Id & Node Id which can then be passed to our processNode() function
    Code:
    nodeId = node.id
    treeId = node.getOwnerTree().getId()
    
    function processNode(treeId, nodeId) {
        var node = Ext.getCmp(treeId).getNodeById(nodeId);
        ..
    }

    ExtJS 4: I understand a tree reference is not put onto the node for V4.
    For example checkchange is only passed the node:
    Code:
    items:[{
    
        id : 'panel1',
        xtype : 'treepanel',
        store : store1,
    
        listeners : {
            checkchange : function(node, checked, eOpts) {
                ..
                }
            }
    
    }]

  10. #10
    Sencha User
    Join Date
    Oct 2011
    Location
    Ukraine
    Posts
    154
    Vote Rating
    6
    Answers
    11
    Romick is on a distinguished road

      0  

    Thumbs up Ok

    Ok


    Create your own tree panel extension whith all neccesary method and events:
    PHP Code:
    Ext.define('Ext.MyTreePanel', {
        
    extend'Ext.tree.Panel',
        
    alias'widget.mytreepanel',
        
        
    initComponent: function(){
          var 
    me this;
               
          
    Ext.apply(me, {
              
    //config
          
    });
          
    me.callParent();
        },
        
        
    processNode: function (nodeId) {
          var 
    me this;
        
          var 
    node me.getNodeById(nodeId);
          ..
        }
        
    //or add "checkchange" event to thow

    or like that:
    PHP Code:
    this.tree Ext.Create('Ext.tree.Panel', {//config});
    ......
    items:[{

        
    id 'panel1',
        
    xtype this.tree,
        
    store store1,

        
    listeners : {
            
    checkchange : function(nodecheckedeOpts) {
                
    this.tree.getNodeById(nodeId);
                ...........
                }
            }
    }] 
    Hope it helps.

Thread Participants: 3