简体   繁体   English

AngularJS:如何给值数组过滤

[英]AngularJS: how to give array of values to filter

How to pass array of values as filter in angularjs 如何在AngularJS中将值数组作为过滤器传递

My scenario 我的情况

cuisines json: ["food", "Alcohol","Thai"] cuisines json: ["food", "Alcohol","Thai"]

catorigeres json : ["home", "office","school"] catorigeres json: ["home", "office","school"]

values with cuisines and categories : 美食和类别的价值:

[{
    "_id": "1",
    "businessTypeName": "Pizza Hut",
    "cus_name": ["food","Thai"],
    "cat_name": ["home", "school"],

}, {
    "_id": "2",
    "businessTypeName": "Chicken Hut",
    "cus_name":["Alcohol","Thai"],
    "cat_name": ["office", "home"],
}, {
    "_id": "3",
    "businessTypeName": "Fish Hut",
    "bussiness_url": "/dist/images/loop_image_sample_3.png",
    "cus_name": ["Thai"],
    "cat_name": ["office", "school"],

}]

cuisines and categories are of in checkbox if i click anyone it will append the array of values to {{selected}} 如果我单击任何菜,都会在复选框中选择美食和类别,它将值数组附加到{{selected}}

my question is how to filter values in {{selected}} to listing_loop div 我的问题是如何将{{selected}}值过滤到listing_loop div

my plunker demo 我的朋克演示

I don't think you can do that in html alone. 我不认为您可以单独在html中做到这一点。

You can add a filtering function to the scope: 您可以向范围添加过滤功能:

$scope.customFilter = function(value, index, array) {
      // make sure `value.id` is a string
      return ["food","Thai","Alcohol"].indexOf(value.id);
}

and using like this in HTML 并在HTML中这样使用

<div ng-repeat="set in get | filter:customFilter"></div>

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM