AngularJs过滤器无法正常工作

时间:2015-02-09 09:36:59

标签: angularjs

请参阅链接
http://plnkr.co/edit/Cn0sNDGEkPOzV19ye8NW?p=preview
我已经更改了我的JSON,然后我无法过滤数据。

var result = $filter('filter')(foo.results, {id:2426})[0];

1 个答案:

答案 0 :(得分:1)

如果限制JSON数据

您可以确保数据属性值为num

也许你可以试试这个......

var foo = {
    "count": 70,
    "language": "en",
    "0": {
      "id": "2420",
      "name": "Medical Center"
    },
    "1": {
      "id": "7840",
      "name": "Conference Room"
    },
    "2": {
      "id": "2426",
      "name": "Deck 5 Starboard"
    }
  };

  foo.results = [];

  for(var property in foo){
    if(property == parseInt(property, 10).toString()){
      foo.results.push(foo[property]);
    }
  }

  var result = $filter('filter')(foo.results, {id:2426})[0];

  $scope.name = result.name;
希望有所帮助!!