Extjs 4为每个项目设置一个id
因此,我正在通过创建监听视图事件以触发方法的控制器来使用遵循 MVC 模式的新 Ext。我有一个视图,其中的树作为管理菜单加载,当单击名为“列出所有用户”的树项目时,我想从“用户”控制器监听,以便我可以显示包含所有用户的网格。我的逻辑是,我必须为每个树元素设置一个 id,以确保我正在监听正确且唯一可能的一个...问题是,即使我将 id 发送到每个元素上的 json,它永远不会被分配。元素 ID 仍然具有“ext-gen1091”类型的元素 ID。
知道如何为每个树元素分配唯一的 id 吗?
我的 json 看起来像这样:
{"expanded":"true","text":"Users","id":"users","children":[{"text":"List all users","id":"userslist"....
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"....
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
您不需要使用 HTML id 来标识您正在处理的记录。 ExtJS 提供的 API 使您可以轻松处理树或其他组件上的操作、监听事件等。
因为,您已经为树中的每个节点分配了 id。当操作/事件发生时,您可以使用相同的 ID 来处理。您所要做的就是向树面板添加适当的事件侦听器方法。例如,如果您要跟踪节点上的点击,则可以使用
itemclick
。方法参数使您可以访问所需的所有信息。这是骨架代码:
同样,您可以利用其他事件并跟踪用户操作。
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:
Similarly you can make use of other events and track user actions.