我的json数据
类别中的类别
[{"id":1,"prev":null,"name":"Hobbies and Gadgets"},{"id":2,"prev":null,"name":"Home and Lifestyle"},{"id":3,"prev":null,"name":"Clothing"},{"id":4,"prev":null,"name":"Entertainment"},{"id":5,"prev":null,"name":"Others"},{"id":6,"prev":1,"name":"Gadgets"},{"id":7,"prev":1,"name":"Designs"},{"id":8,"prev":1,"name":"Music"},{"id":9,"prev":1,"name":"Photography"},{"id":10,"prev":1,"name":"Books"}]
我的代码
datalist#categoryList
option(data-ng-repeat="category in categories" value="{{category.name}}")
它显示所有category.name。
我只想显示category.prev
中具有空值的category.name答案 0 :(得分:1)
您可以使用filter来执行此操作
option(data-ng-repeat="category in categories | filter:{prev:null}" value="{{category.name}}")
var app = angular.module('my-app', [], function() {})
app.controller('AppController', function($scope) {
$scope.categories = [{
"id": 1,
"prev": null,
"name": "Hobbies and Gadgets"
}, {
"id": 2,
"prev": null,
"name": "Home and Lifestyle"
}, {
"id": 3,
"prev": null,
"name": "Clothing"
}, {
"id": 4,
"prev": null,
"name": "Entertainment"
}, {
"id": 5,
"prev": null,
"name": "Others"
}, {
"id": 6,
"prev": 1,
"name": "Gadgets"
}, {
"id": 7,
"prev": 1,
"name": "Designs"
}, {
"id": 8,
"prev": 1,
"name": "Music"
}, {
"id": 9,
"prev": 1,
"name": "Photography"
}, {
"id": 10,
"prev": 1,
"name": "Books"
}];
})

<script src="https://ajax.googleapis.com/ajax/libs/angularjs/1.4.4/angular.js"></script>
<div ng-app="my-app">
<div ng-controller="AppController">
<select>
<option data-ng-repeat="category in categories | filter:{prev:null}" value="{{category.name}}">{{category.name}}</option>
</select>
</div>
</div>
&#13;