如何JSON-数据与AngularJs过滤? [英] How to filter JSON-Data with AngularJs?

查看:127
本文介绍了如何JSON-数据与AngularJs过滤?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个数组(_users),其中包含JSON对象。

I have an array (_users) that contains JSON objects.

{ 
  "User":
  {
    "userid":"19571",
    "status":"7",
    "active":"1",
    "lastlogin":"1339759025307",
    "Stats":
     [
       {
         "active":"1",
         "catid":"10918",
         "typeid":"71",
         "Credits":
         [
           {
             "content":"917,65",
             "active":"1",
             "type":"C7"
           },               
           {
             "content":"125,65",
             "active":"1",
             "type":"B2"
           }
         ]
       }
     ]
  }
}

1 - 我如何才能只过滤与用户主动:1不是0

1- How can I filter only users with "active":"1" not "0"

我已经试过这样的事情:

I have tried something like this:

<div ng-repeat="user in _users | filter:active | orderBy:user.userid">
    {{user.userid}}
</div>

但不是为我工作正常。

but not working correctly for me.

感谢您!

推荐答案

由于你的对象模型很复杂,我会建议使用自定义过滤功能:

Since your object model is kind of complex I would recommend using custom filtering function:

$scope.isActive = function(user) {
    return user.User.Stats[0].active === "1";
};

,然后在你的HTML:

and then in your HTML:

<div ng-repeat="user in _users | filter:isActive">
    {{user.User.userid}}
</div>

下面是工作的jsfiddle:<一href=\"http://jsfiddle.net/pkozlowski_opensource/4kzzy/3/\">http://jsfiddle.net/pkozlowski_opensource/4kzzy/3/

Here is the working jsFiddle: http://jsfiddle.net/pkozlowski_opensource/4kzzy/3/

请务必检查角度的文档上的过滤器,如果你需要更多的信息:<一href=\"http://docs.angularjs.org/api/ng.filter:filter\">http://docs.angularjs.org/api/ng.filter:filter

Be sure to check angular's documentation on filters if you need more info: http://docs.angularjs.org/api/ng.filter:filter

这篇关于如何JSON-数据与AngularJs过滤?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆