Dojo 有没有办法找到 DOM 元素中的所有小部件后代?
Dojo 有没有办法找到 DOM 元素中的所有小部件后代?我使用下面的示例,它只会列出元素的子元素,在这种情况下,属于文档对象子元素的任何小部件,但不是所有后代或嵌套小部件。希望这是清楚的。
var widgets = dijit.findWidgets(dojo.doc);
dojo.forEach(widgets, function(w) {
console.log(w);
});
我可以编写自己的递归函数,但我想确保我不会错过已经执行此操作的 Dojo 方法。
非常感谢
Is there a way in Dojo to find all widget descendants in a DOM element? I used the example below it will only list the children of the element, in this case any widgets that are children of the document object, but not all the descendants or nested widgets. Hopefully that's clear.
var widgets = dijit.findWidgets(dojo.doc);
dojo.forEach(widgets, function(w) {
console.log(w);
});
I could just write my own recursive function but I want to make sure I'm not missing out on a Dojo method which already does this.
Many thanks
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
嗯,dijit.findWidgets(parentWidget.domNode)
?编辑哦,现在我需要findWidgets不递归搜索。
我检查了 dijit.findWidgets 源代码,它所做的只是检查 dijit 注册表中具有
widgetid
属性的节点。以下版本使用 dojo.query 递归地执行相同的搜索:Hmm,dijit.findWidgets(parentWidget.domNode)
?Edit Oh, now I nee findWidgets doesn't search recursively.
I checked the dijit.findWidgets source code and all it does is check for nodes with a
widgetid
attribute that are represented in the dijit registry. The following version uses dojo.query to do this same search recursively: