1. #1
    Sencha Premium Member
    Join Date
    Apr 2011
    Location
    Chicago, IL
    Posts
    65
    Answers
    3
    Vote Rating
    11
    ccg will become famous soon enough

      0  

    Default Answered: How do I get the currently visible node/leaf in a NestedList?

    Answered: How do I get the currently visible node/leaf in a NestedList?


    When using a treeStore in a NestedList, is there a way to get a reference to the node or leaf (a Model or NodeInterface object) that is currently visible?

    I have a treeStore with data like this:

    Code:
    [
      {
        title: 'hello',
        info: 'foo',
        leaf: false,
        children: [
          {
            title: 'hello.1',
            leaf: false,
            children: [...]
          },
          {
            title: 'hello.2',
            leaf: false,
            children: [...]
          }
        ],
      },
      {
        title: 'goodbye',
        info: 'bar',
        leaf: false,
        children: [...]
      }
    ]
    I use that treeStore to set up a nestedlist for navigation. When the user clicks the "Info" button in the toolbar, I need to be able to get the currently visible node or leaf and climb up the tree (node.parentNode...) until I find a record that has the "info" field defined, because "info" is only available on the top-level nodes right below the root, and that value applies to all child nodes.

    That's why I'd like to be able to query the nestedlist for the currently visible leaf or node. Is that possible?

    I'm thinking about routing around the problem by adding a listener to the nestedlist's 'selectionchange' event and storing a reference to the selected node that I can lookup later if the user taps the "Info" button, but I think that's ugly.

    Thanks!
    chad

  2. You could get the current Node based off the current active items store.

    Code:
    YourNestedList.getActiveItem().getStore().getNode();

  3. #2
    Sencha Premium Member
    Join Date
    Feb 2010
    Location
    Chicago
    Posts
    34
    Answers
    10
    Vote Rating
    8
    Johnny Major will become famous soon enough

      0  

    Default


    You could get the current Node based off the current active items store.

    Code:
    YourNestedList.getActiveItem().getStore().getNode();

  4. #3
    Sencha Premium Member
    Join Date
    Apr 2011
    Location
    Chicago, IL
    Posts
    65
    Answers
    3
    Vote Rating
    11
    ccg will become famous soon enough

      0  

    Default


    Thanks! That did it.

    Would you happen to know what kind of setup needs to happen to have NestedList.getActiveItem() return an Ext.dataview.List instance instead of the default value of the number 0 (zero)? I tried to write a Jasmine test for this code with some hard-coded test data in the store and an instance of the view rendered directly into a hidden DIV, and even though the code works fine in the real app, the test fails, because getActiveItem() is returning 0 (integer zero) when running under Jasmine.

    BTW, thanks for hosting the Chicago Sencha meetup. See you guys Thursday. :-)

  5. #4
    Sencha Premium Member
    Join Date
    Feb 2010
    Location
    Chicago
    Posts
    34
    Answers
    10
    Vote Rating
    8
    Johnny Major will become famous soon enough

      0  

    Default


    I would have to assume your NestedList doesn't have a store. You would see a value of 0 via getActiveItem if the store was not supplied to the NestedList.

    Quick test with a hidden div "hList"

    Code:
            Ext.get('hList').appendChild(Ext.create('Ext.NestedList', {
                id : 'testList',
                title: 'Groceries',
                displayField: 'text',
                store: store
            }).element);
    getActiveItem returns the list however if you remove the store as shown below getActiveItem returns 0

    Code:
            Ext.get('hList').appendChild(Ext.create('Ext.NestedList', {
                id : 'testList',
                title: 'Groceries',
                displayField: 'text'
            }).element);
    See you Thursday!!!

Thread Participants: 1