[英]Selecting a subarray in a javascript object using jQuery/jHashtable
I have an object like this: 我有一个这样的对象:
var data = {
"info" : [{
"title": "Desemberkonsert",
"description": "MangerFHS 09/10"
}],
"playlist" : [
{
"title": "In This Place",
"description": "Excalibur",
"href": "desemberkonsert_in-this-place",
"url": "flv/desemberkonsert/21_in_this_place.flv",
"thumbnail": "flv/desemberkonsert/21_in_this_place_thumbnail.png",
"time": "5:39"
}]
}
And I am trying to do a search using jHashtables containsValue-function (I am willing to settle for any other search method that works though), like this containsValue(data.playlist, 'Excalibur')
. 而且我正在尝试使用jHashtables containsValue-function进行搜索(我愿意解决其他适用的搜索方法),例如
containsValue(data.playlist, 'Excalibur')
。 But for some reason, this returns false . 但是由于某种原因,它返回false 。 How would I select the array that contains the the value Excalibur from the code above?
如何从上面的代码中选择包含值Excalibur的数组?
I could not find a decent method inherently available in JavaScript or the jQuery library, but using a smaller library named jLinq ( http://jlinq.hugoware.com/ ), doing it was a breeze. 我找不到JavaScript或jQuery库内在可用的体面方法,但是使用名为jLinq( http://jlinq.hugoware.com/ )的较小库,这很容易。 It allows me to filter with many different methods (I am using the 3.x beta though).
它允许我使用许多不同的方法进行过滤(尽管我正在使用3.x beta)。
EDIT: The thing I missed was that the lowest arrays behave like objects too. 编辑:我想念的是最低的数组也像对象一样。 But as Šime Vidas pointed out, I can select a subarray like this:
data.playlist[0]
, and an item within that like this: data.playlist[0].description
. 但是正如ŠimeVidas指出的那样,我可以选择一个子
data.playlist[0]
: data.playlist[0]
,并在其中选择一个项目: data.playlist[0].description
。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.