如何查询dojo中的对象类型? [英] How to query on object type in dojo?

查看:119
本文介绍了如何查询dojo中的对象类型?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我们可以使用dojo.query来获取基于CSS选择器的某些元素,但是我们如何查询对象类型?

例如,获取页面上的所有TextBox元素,然后使用dojo.connect绑定函数?

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?

推荐答案

这不是完全支持的,但是有两种方法可以看到它。

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

其中一个,找出一个TextBox的唯一类( .dijitTextBox ),调用 dojo.query('。dijitTextBox'),循环结果 dojo.forEach ,并使用 dijit.getEnclosingWidget(domnode)

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));
});

或者两个,循环 dijit.registry._hash ,test declaredClass ,如果它的 dijit.form.TextBox - connect。

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';
})

根据您的设置,选择最有效的一个。后者通常是最好的 - 除非你的页面中有100个小部件。第一个将不得不xpath所有页面的元素。 Allthough,记住dojo.query将第二个参数作为parentNode

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'

这篇关于如何查询dojo中的对象类型?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆