How to query on object type in dojo?

不羁的心 提交于 2019-12-02 12:07:14

问题


We can use dojo.query to get certain elements based of CSS selectors but how do we query on object types?
For example, get all the TextBox elements on the page and then use dojo.connect to bind a function?


回答1:


This is not completely supported, yet there are two ways of doing it as i see it.

One, figure out which is the unique class for a TextBox (.dijitTextBox), call dojo.query('.dijitTextBox'), loop result dojo.forEach and get the widget with dijit.getEnclosingWidget(domnode)

var textboxArray = [];
dojo.forEach(dojo.query('.dijitTextBox'), function(domnode) {
  textboxArray.push(dijit.getEnclosingWidget(domnode));
});

Or two, loop the dijit.registry._hash, test declaredClass, if its dijit.form.TextBox - connect.

var textboxArray = dojo.filter(dijit.registry._hash, function(widget) {
  return widget.declaredClass && widget.declaredClass == 'dijit.form.TextBox';
})

Depending your setup, choose the most efficient one. The latter is commonly best - unless you have 100's of widgets in your page. The first will have to xpath all your elements of the page. Allthough, remember that dojo.query takes a second parameter as 'parentNode'



来源:https://stackoverflow.com/questions/12023343/how-to-query-on-object-type-in-dojo

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!