gpt4 book ai didi

jquery - Jquery 中原型(prototype) .any 的等价物是什么?

转载 作者:行者123 更新时间:2023-12-03 22:00:29 25 4
gpt4 key购买 nike

我们在 Prototype 中有一个名为 .any 的函数。我想要像 Jquery 一样的。

我的原型(prototype)代码是:

 if (item_name == '' || $R(1,ind).any(function(i){return($F("bill_details_"+i+"_narration") == item_name)})) {
alert("This item already added.");
}

我想使用 Jquery 执行等效函数。

请帮助我实现所需的输出。提前致谢..

最佳答案

对于 IE 9+,它是内置的:

The some() method tests whether some element in the array passes the test implemented by the provided function.

https://developer.mozilla.org/en/docs/Web/JavaScript/Reference/Global_Objects/Array/some

[2, 4, 6, 8, 10].some(function(n) { return n > 5; });
// -> true (the iterator will return true on 6)

对于 IE 8 及以下版本:

原型(prototype) any

[2, 4, 6, 8, 10].any(function(n) { return n > 5; });
// -> true (the iterator will return true on 6)

您可以使用jQuery.grep:

jQuery.grep([2, 4, 6, 8, 10], function(n) { return n > 5; }).length > 0;
// -> true (as grep returns [6, 8, 10])

下划线_.any_.some

_.any([2, 4, 6, 8, 10], function(n) { return n > 5; });
// -> true (the iterator will return true on 6)

关于jquery - Jquery 中原型(prototype) .any 的等价物是什么?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/15657115/

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