如何使用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视图中的数据,我希望显示所有内容 特定标签字段的'标签'名称 具体 id
我从所有id
中获取了标签名称示例:
<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>
我会非常感谢最好的解决方案..因为我有替代解决方案,但这不是最好的做法
答案 0 :(得分:1)
如果我正确理解您的问题,您可以使用过滤器。 https://docs.angularjs.org/api/ng/filter/filter
<div class="col-sm-8" ng-repeat="tags in addProjectVm.tagsData | filter:{type:'Project Type'}">
&#13;
这是一个小提琴: http://jsfiddle.net/4o7dwyu6/
答案 1 :(得分:0)
我在这里看不到需要填充内容,只需使用ng-if
显示您想要的标记:
<label ng-repeat="tag in tags.Tags" ng-if="tag.type === 'Project Type'">
答案 2 :(得分:0)
我这样做了..
DECLARE @statusList varchar(500)
select distinct '['+ cast(SUBJECT_STATUS as varchar)+']' as subject_status
into temp
FROM YourTable
select @statusList= COALESCE(@statusList + ',', '')+ cast(SUBJECT_STATUS as varchar)
FROM temp
drop table temp
DECLARE @sql varchar(1000)
SET @sql = '
select * from
(select STUDENT_COUNT,SUBJECT_NAME,SUBJECT_STATUS
from YourTable) sub
pivot (
sum(STUDENT_COUNT)
FOR SUBJECT_STATUS
IN ('+@statusList+')
) piv;'
EXEC (@sql)