angular.js - angular里的filter过滤数据传参问题
漂亮男人
漂亮男人 2017-05-15 17:08:49
0
2
841

控制器:$scope.dataList=[

{"dataClass":"0","dataName":"A1"}, {"dataClass":"0","dataName":"A2"}, {"dataClass":"1","dataName":"B1"}, {"dataClass":"1","dataName":"B2"}, {"dataClass":"2","dataName":"C1"}, {"dataClass":"2","dataName":"C2"}

]
HTML模板:

  • {{item.dataName}}

  • 页面展示将循环过滤出dataList数组中dataClass为'0'的A1,A2;现在的需求是dataClass过滤的值是一个变量设为varity,而ng-repeat="item in dataList |filter :{'dataClass':varity}",又不生效,请问如何实现该需求

    漂亮男人
    漂亮男人

    reply all (2)
    为情所困

    I wrote a filter for you and removed the specified dataClass:

    angular.module('common', []).filter('myFilter', function () { return function (collection, keyname,value) { var output = []; angular.forEach(collection, function (item) { //过滤数组中值与指定值相同的元素 if(item[keyname]!=value){ output.push(item); } }); return output; } });

    {{x.dataClass}}---{{x.dataName}}

    The filter receives 3 parameters, the original array, the key to be filtered, and the specified key value.

      phpcn_u1582
      repeat="item in dataList |filter :{'dataClass':{{varity}} }"

      Just add curly brackets

        Latest Downloads
        More>
        Web Effects
        Website Source Code
        Website Materials
        Front End Template
        About us Disclaimer Sitemap
        php.cn:Public welfare online PHP training,Help PHP learners grow quickly!