How to filter the object inside object in angular 2? -
i have json this:
filteredarray = [ { "key":"brochure", "value":[{ "title":"accounting services", "service":"accounting", "location":"", "industry":"accounting", "reprint":"request", "contact":"mike astrup", "updated":"04/15/2017", "owner":"eb", "status":"approved", "online":"true", "type":"material", "url":".common/service" }, { "title":"accounting services", "service":"accounting", "location":"", "industry":"", "reprint":"request", "contact":"mike astrup 1", "updated":"04/15/2017", "owner":"eb", "status":"approved", "online":"true", "type":"material", "url":".common/service" }] }, { "key":"handout", "value":[{ "title":"accounting services", "service":"accounting", "location":"", "industry":"", "reprint":"request", "contact":"mike astrup 2", "updated":"04/15/2017", "owner":"eb", "status":"approved", "online":"true", "type":"material", "url":".common/service" }, { "title":"accounting services", "service":"accounting", "location":"", "industry":"", "reprint":"request", "contact":"mike astrup 3", "updated":"04/15/2017", "owner":"eb", "status":"approved", "online":"true", "type":"material", "url":".common/service" }] } ] i have filter data on bases of industry in angular 2.
i using query in pipe in angular 2 data not getting filtered.
filteredarray.filter( item => item.value.filter( inneritem => inneritem.industry.match(industry)))
make use of array.filter , array.some
let s = this.data.filter((d) => { d.value = d.value.filter(d1 => { if (d1.industry === "accounting") { // here put condition return d1; } }); if (d.value.length > 0) { return d; } }); var data = [ { "key":"brochure", "value":[{ "title":"accounting services", "service":"accounting", "location":"", "industry":"accounting", "reprint":"request", "contact":"mike astrup", "updated":"04/15/2017", "owner":"eb", "status":"approved", "online":"true", "type":"material", "url":".common/service" }, { "title":"accounting services", "service":"accounting", "location":"", "industry":"", "reprint":"request", "contact":"mike astrup 1", "updated":"04/15/2017", "owner":"eb", "status":"approved", "online":"true", "type":"material", "url":".common/service" }] }, { "key":"handout", "value":[{ "title":"accounting services", "service":"accounting", "location":"", "industry":"", "reprint":"request", "contact":"mike astrup 2", "updated":"04/15/2017", "owner":"eb", "status":"approved", "online":"true", "type":"material", "url":".common/service" }, { "title":"accounting services", "service":"accounting", "location":"", "industry":"", "reprint":"request", "contact":"mike astrup 3", "updated":"04/15/2017", "owner":"eb", "status":"approved", "online":"true", "type":"material", "url":".common/service" }] } ]; var s = data.filter((d) => { d.value = d.value.filter(d1 => { if(d1.industry === "accounting") { return d1; } }); if(d.value.length > 0){ return d; } }); console.log(s);
Comments
Post a Comment