gpt4 book ai didi

javascript - 如何限制我的 ng-repeat 值

转载 作者:行者123 更新时间:2023-12-03 08:49:18 25 4
gpt4 key购买 nike

我的 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
选项(data-ng-repeat =“类别中的类别”值=“{{category.name}}”)

它显示所有类别.名称。

我只想显示在category.prev中具有空值的category.name

最佳答案

您可以使用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>

关于javascript - 如何限制我的 ng-repeat 值,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/32753142/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com