let data = [{
"id": 31,
"city_id": 13,
"title": "五村名",
"description": "",
"status_id": 4,
"latitude": "31.238146",
"longitude": "121.414987",
"address": "曹杨五村",
"content": "",
"image": null,
"visible": 1,
"allow_comment": 1,
"is_open": 0,
"city": {
"id": 13,
"parent_id": 0,
"name": "上海市"
},
"status": {
"id": 4,
"name": "自有冰箱"
}
},
{
"id": 32,
"city_id": 13,
"title": "四村名",
"description": "",
"status_id": 3,
"latitude": "31.243508",
"longitude": "121.41411",
"address": "曹杨四村",
"content": "",
"image": null,
"visible": 1,
"allow_comment": 1,
"is_open": 0,
"city": {
"id": 13,
"parent_id": 0,
"name": "上海市"
},
"status": {
"id": 3,
"name": "专柜"
}
},
{
"id": 33,
"city_id": 13,
"title": "八村名",
"description": "",
"status_id": 2,
"latitude": "31.253715",
"longitude": "121.414496",
"address": "曹杨八村",
"content": "",
"image": null,
"visible": 1,
"allow_comment": 1,
"is_open": 0,
"city": {
"id": 13,
"parent_id": 0,
"name": "上海市"
},
"status": {
"id": 2,
"name": "有店"
}
}]
有这么个数组,需要遍历检索数据,比如想搜索 有店
这个关键字 遍历这个数组,当匹配到当前对象的所有key值
有这个关键字的时候就会添加到一个 新的数组里面。
不只是搜索 status.name
这一个 ,也需要模糊匹配 address
要模糊匹配 对象的所有key
值
这个是叫 全文搜索吗。
推荐用underscore.js
_.filter(data, function(item){ return item.status.name.includes('有店')=== true; });