是否有任何jQuery的功能来查询多维数组以类似的方式向DOM? [英] Are there any jquery features to query multi-dimensional arrays in a similar fashion to the DOM?

查看:133
本文介绍了是否有任何jQuery的功能来查询多维数组以类似的方式向DOM?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

有什么问题说...

jQuery的是否有可以让你查​​询以类似的方式对象的MULT维数组,因为它与DOM做任何方法。

Does jQuery have any methods that will allow you to query a mult-dimensional array of objects in a similar fashion as it does with the DOM.

因此​​,举例来说,让我有一些匹配的属性值包含多维数组中的对象的列表 - 例如当StartOfPeriod比指定日期大于或其中名称==奔雪花

So for instance, get me a list of objects contained within a multi-dimensional array having some matching property value - for instance where StartOfPeriod greater than a specified date or where name == "Ben Alabaster"

我想,以避免重新发明轮子,如果有什么东西已经在那里。

I'd like to avoid re-inventing the wheel if there's something already out there.

推荐答案

您不能使用选择语法,但jQuery提供的 $。gr​​ep的 $ .inArray ,它可以是对这项有益的。 的grep 返回匹配predicate的元素的新数组。 inArray 返回第一个匹配元素的索引,或-1。例如:

You can't use selector syntax, but jQuery comes with $.grep and $.inArray, which can be useful for this. grep returns a new array of elements that match a predicate. inArray returns the index of the first matching element, or -1. For instance:

var matches = $.grep(array, function(el){
  return el.StartOfPeriod > 2000;
});

这是类似于标准ECMAScript的方法, Array.filter (simimlar到的grep )和的 Array.indexOf (类似于 inArray ); jQuery的实际使用 Array.indexOf (如有)。还有其他有用的ECMAScript的方法,如 阵列。每 (所有元素匹配)和的 Array.some (至少有一个匹配)。 MDC有code,可添加到您的项目,所以在浏览器中,这些工作没有本机实现。

These are similar to the standard ECMAScript methods, Array.filter (simimlar to grep) and Array.indexOf (similar to inArray); jQuery actually uses Array.indexOf where available. There are also other useful ECMAScript methods, such as Array.every (all elements matching) and Array.some (at least one matching). MDC has code you can add to your project so these work in browsers that don't have native implementations.

这篇关于是否有任何jQuery的功能来查询多维数组以类似的方式向DOM?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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