ng-repeat过滤器不过滤掉空值

时间:2015-06-08 12:37:30

标签: angularjs angularjs-ng-repeat

JSON:

$scope.results=[
    {
        id: 1,
        name: null,
        class: "First"
    },
    {
        id: 2,
        name: John,
        class: "First"
    },
    {
        id: 3,
        name: Mary,
        class: "Second"
    },
    {
        id: 4,
        name: null,
        class: "Third"
    }

]

HTML:

 <div class="col-md-6 form-group" data-ng-repeat="item in results| filter:{name:'!null'}">{{item.name}}</div>

我想过滤掉namenull的数据。我的代码出了什么问题?

2 个答案:

答案 0 :(得分:0)

通过添加这段代码来解决它:

 <div class="col-md-6 form-group" data-ng-repeat="item in results| filter:{name:'!!'}">{{item.name}}</div>

答案 1 :(得分:0)

你的json formate不合适试试这个

plunker link http://plnkr.co/edit/H94f6XhyyhbvJ3F25NoA?p=preview

$scope.results=[
{
    id: 1,
    name: null,
    class: "First"
},
{
    id: 2,
    name: "John",
    class: "First"
},
{
    id: 3,
    name: "Mary",
    class: "Second"
},
{
    id: 4,
    name: null,
    class: "Third"
}
];