angularjs filter (not working)

前端 未结 7 1301
灰色年华
灰色年华 2020-12-25 14:56

The following HTML, Javascript and JSON render correctly, but the filter does not work at all. What are we doing wrong?



        
相关标签:
7条回答
  • 2020-12-25 15:52

    As Narretz already mentioned, Angular filters cannot handle an object of objects as input. But you can write your own simple filter converting the object of objects into an array of objects. You can use the angular filters behind your array filter by chaining.

    <ul data-ng-repeat="catalog in catalogs | array | filter:catalog_filter">
    

    Your array filter could be as simple as this:

    app.filter('array', function() {
      return function(items) {
        var filtered = [];
        angular.forEach(items, function(item) {
          filtered.push(item);
        });
       return filtered;
      };
    });
    
    0 讨论(0)
提交回复
热议问题