-
22 Feb 2013 3:16 PM #1
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:
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.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: [...] } ]
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
-
Best Answer Posted by Johnny Major
You could get the current Node based off the current active items store.
Code:YourNestedList.getActiveItem().getStore().getNode();
-
23 Feb 2013 8:57 AM #2
You could get the current Node based off the current active items store.
Code:YourNestedList.getActiveItem().getStore().getNode();
-
25 Feb 2013 4:43 PM #3
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. :-)
-
25 Feb 2013 6:47 PM #4
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"
getActiveItem returns the list however if you remove the store as shown below getActiveItem returns 0Code:Ext.get('hList').appendChild(Ext.create('Ext.NestedList', { id : 'testList', title: 'Groceries', displayField: 'text', store: store }).element);
See you Thursday!!!Code:Ext.get('hList').appendChild(Ext.create('Ext.NestedList', { id : 'testList', title: 'Groceries', displayField: 'text' }).element);


Reply With Quote