Question

So i'm working with the new Ext following MVC patterns by creating controllers which listen to view events to fire methods. I have a view with a tree loaded as an admin menu and I want to listen from the 'Users' controller when the tree item called 'List all users' is clicked so I can show the grid with all users. My logic says that I have to set an id to each tree element in order to make sure I'm listening to the right and only possible one...problem is, even though I send and id to my json on each element, it never gets assigned. The element ids still have the 'ext-gen1091' type of element ids.

Any idea how do I do about assigning a unique id to each of my tree elements?

My json looks like this:

{"expanded":"true","text":"Users","id":"users","children":[{"text":"List all users","id":"userslist"....
Was it helpful?

Solution

You don't need to use HTML ids to identify the record you are handling. ExtJS provides APIs that make it easy for you to handle operations, listen to events etc on the tree or other components.

Since, you already have id assigned to each node in the tree. You can use the same id to work upon when an action / event occurs. All you have to do is add appropriate event listener methods to the tree panel. For example if you are tracking click on a node you can make use of the itemclick. The methods parameters provide you access to all information you will need.

here is the skeleton code:

itemclick: function(Ext.view.View this, Ext.data.Model record, HTMLElement item, Number index, Ext.EventObject e) {
   // Access the record using record or you can access the HTML using item variable.
}

Similarly you can make use of other events and track user actions.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top