在jquery中过滤一个对象 [英] filter an object in jquery
问题描述
$(this).find('li')。每个(函数(){
var $ itm = $(this);
localproducts.push({$ b $'dataid':$ itm.attr('data-id'),
'datapackage':$ itm.attr('data-package'),
'packageid':($ itm.children('.packidid').text())
});
});
现在我要过滤创建的对象localproducts,例如。我想保存packageid等于3的所有项目的dataid。我认为这可以用数组过滤器来完成,但不知道如何。任何帮助?谢谢!
过滤器
var matching = $(localproducts).filter(function(){
return this.packageid == 3;
});
使用 示例: http://jsfiddle.net/hunter/tqTDQ/ I have an object which I have created as follows: now I want to filter the created object localproducts, eg. I want to save all the dataids of items whose packageid is equal to 3 for example. I think it can be done with array filter but not sure how. Any help? thanks! using
using
Example: http://jsfiddle.net/hunter/tqTDQ/ 这篇关于在jquery中过滤一个对象的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋! code $>
$ $ p $ var dataids = new Array();
$ b $(localproducts).each(function(){
if(this.packageid == 3)dataids.push(this.dataid);
});
$(this).find('li').each(function(){
var $itm = $(this);
localproducts.push({
'dataid' : $itm.attr('data-id'),
'datapackage' : $itm.attr('data-package'),
'packageid' : ($itm.children('.packageid').text())
});
});
filter
var matching = $(localproducts).filter(function(){
return this.packageid == 3;
});
each
var dataids = new Array();
$(localproducts).each(function(){
if (this.packageid == 3) dataids.push(this.dataid);
});