gpt4 book ai didi

javascript - Dojo - 如何在另一个 forEach 内的选定节点上使用 forEach

转载 作者:行者123 更新时间:2023-11-29 10:51:51 24 4
gpt4 key购买 nike

在 jQuery 中我会这样做:

var foo = jQuery("form");
foo.each(function(){
this.find(".required").each(function(){...})
})

这会找到当前处理的表单中的每个必填字段。

但是因为我必须使用 Dojo,所以我有点迷路了。在 Dojo 中你需要使用 dojo.forEach()

    var foo = dojo.query("form");
dojo.forEach(foo, function(self,i){

// And now I have no idea on what to use the forEach.
// The "self" parameter is the form node. So now I
// would need something like `self.forEach`
// But that obviously does not work

}

最佳答案

你只需要再做一次查询,就像你在第一关所做的那样。 Dojo 中的理念是事物通常没有 jQuery 中的那么“神奇”。

var forms = dojo.query("form"); //No second argument; Searches whole document
dojo.forEach(forms, function(form){
var requireds = dojo.query(".required", form);//Only search under
// the current form.
dojo.forEach(requireds, function(required){
/* do stuff*/
});
})

我还冒昧地更改了 self 变量的名称(因为与 jQuery 不同,Dojo 不会更改 this)并从中删除了可选的 i 参数forEach。

关于javascript - Dojo - 如何在另一个 forEach 内的选定节点上使用 forEach,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/8716144/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com