gpt4 book ai didi

javascript - 如何在 Angular JS 中使用 ng-repeat 填充数组

转载 作者:行者123 更新时间:2023-11-30 00:19:51 24 4
gpt4 key购买 nike

如何使用 ng-repeat 为 AngularJS 1.4 版中的特定 id 填充对象数组

{
"tagTypeDetails": [
{
"id": 3,
"type": "Project Type",
"Tags": [
{"id": 21, "name": "Residential"},
{"id": 22, "name": "Office"},
{"id": 23, "name": "Retail"},
{"id": 24, "name": "Hospitality"}
]
},
{
"id": 6,
"type": "Styles",
"Tags": [
{"id": 47, "name": "Scandinavian"},
{"id": 48, "name": "Industrial"},
{"id": 49, "name": "Contemporary"},
{"id": 50, "name": "Minimalistic"},
{"id": 51, "name": "Modern"},
{"id": 52, "name": "Eclectic"}
]
},
{
"id": 9,
"type": "Area",
"Tags": [
{"id": 68, "name": "500-1000 sqft"}
]
},
{
"id": 30,
"type": "Project Budget",
"Tags": [
{"id": 112 ...}
],
...
}
]
}

这是 html View 中的数据 我想显示所有'Tags' name 基于特定的特定标签字段具体id

我正在从所有 id 中获取标签名称

Example :

<label for="type" class="col-sm-2">Project type</label>
<div class="col-sm-8" ng-repeat="tags in addProjectVm.tagsData">
<label ng-repeat="tag in tags.Tags">
//here all Tags name are getting displayed.. //i want specific for type="Project Type" only
<input type="checkbox" name="project" id="{{tag.id}}" value="{{tag.name}}"> {{tag.name}}
</label>
</div>

如果有最好的解决方案,我将不胜感激..因为我有替代解决方案,但这不是最佳做法

最佳答案

如果我正确理解您的问题,您可以使用过滤器。 https://docs.angularjs.org/api/ng/filter/filter

<div class="col-sm-8" ng-repeat="tags in addProjectVm.tagsData | filter:{type:'Project Type'}">

这是一个 fiddle : http://jsfiddle.net/4o7dwyu6/

关于javascript - 如何在 Angular JS 中使用 ng-repeat 填充数组,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/33579704/

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