0

与我的问题相关,我在获取所有元素时遇到了麻烦,我想使用dojo.query 我的代码获取类的所有元素,如下所示;

var jsonRoles = {"roles": [
                            {"roleId": "1", "roleName": "role1", "roleDesc": "This is role1"},
                            {"roleId": "2", "roleName": "role2", "roleDesc": "This is role2"},
                            {"roleId": "3", "roleName": "role3", "roleDesc": "This is role3"}
                        ]
                    };
                    var results="";
                    for(var i=0;i<jsonRoles.roles.length;i++){
                        results += '<div class="dojoDndItem ">' + '<span style="visibility: hidden">' + jsonRoles.roles[i].roleId + '</span>' + jsonRoles.roles[i].roleName  + '</div>';
                    }
                    var list = dojo.query(".dojoDndItem");

我想将具有类名的元素存储dojoDndItem在变量“ list ”中,但是当我在firebug中检查“ list ”时,它给了我“[]”(空数组)。难道我做错了什么?

4

1 回答 1

0

dojo.query returns an array of matching DOM nodes from the page based on a CSS selector.

The variable results in your question is just a string with text like:

<div class="dojoDndItem"><span style="visibility: hidden">...

It's just a string. It's not an array of DOM elements, nor have you added any new elements to the page DOM itself, so unless there are pre-existing elements with the dojoDndItem class, empty array [] is the correct result.

于 2012-05-01T08:29:42.067 回答