离子两个阵列 [英] Ionic two arrays
本文介绍了离子两个阵列的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
有两个数组,即menuitems和posts。
There are two arrays, namely menuitems and posts.
我想通过以下方式过滤与menuitems具有相同ID的帖子:
I would like to filter posts that has the same ID with those in menuitems by doing something like:
this.menuitems = this.menuitems.filter((item) =>{
return item.eName.toLowerCase().indexOf(dishname.toLowerCase()) > -1 })
this.posts = this.posts.filter( function(e){ return e.restaurantID == this.menuitems; });
Json的帖子:
{
"restaurantID": "20180322",
"avgPrice": 99,
"avgRate": 50,
"cName": "tt",
"eName": "test",
"cAddress": "tt",
"eAddress": "test",
"logo": "111",
"cCuisine": "",
"eCuisine": "Cantonese",
"startsat": "2018-03-21 00:00:00"
}
json for menuitems:
Json for menuitems:
{
"menuID": "test02",
"RestaurantID": "20180322",
"catID": null,
"eDescription": null,
"cDescription": null,
"price": 99,
"setPrice": 8,
"orderCode": 9,
"eName": "test",
"cName": "tt",
"cCategory": null,
"eCategory": null
}
但它不起作用!提前致谢!
But it doesn't work! Thanks in advance!
推荐答案
也许是这样的:
let flatMenu = this.menuItems.map(function(obj) {return obj.RestaurantID; })
for(let i = 0; i<this.posts.length; i++) {
let objectFound = flatMenu.indexOf(this.posts[i].restaurantID)
if (objectFound == -1) { this.posts[i] = null}
}
请记住,js区分大小写。
And remember, js is case sensitive.
这篇关于离子两个阵列的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文