gpt4 book ai didi

javascript - 如何循环遍历angularjs中的对象数组

转载 作者:行者123 更新时间:2023-12-03 01:42:20 27 4
gpt4 key购买 nike

我有一个像这样的对象:

{
"batman":[{"applicantSkillID":"htl2","rating":3,"applicantInterviewerID":"usr1","applicantInterviewerName":"batman","applicantSkillName":"HTML"},
{"applicantSkillID":"cs43","rating":5,"applicantInterviewerID":"usr1","applicantInterviewerName":"batman","applicantSkillName":"css"}],

"Superman":[{"applicantSkillID":"ht12","rating":3,"applicantInterviewerID":"usr2","applicantInterviewerName":"Superman","applicantSkillName":"HTML"},
{"applicantSkillID":"cs43","rating":3,"applicantInterviewerID":"usr2","applicantInterviewerName":"Superman","applicantSkillName":"css"}]
}

现在我正在尝试明智地显示数据applicantInterviewerName( bat 侠的评分、超人的评分等..)

对于只有一个applicantInterviewerName,我可以通过获取第一个对象索引来做到这一点,如下所示:

<tbody class="table text-left boxShade displayTable">
<tr ng-repeat="feedBack in c.data.interviewerFeedback">
<td class="skillName" id="{{feedBack.applicantSkillID}}"> {{feedBack.applicantSkillName}}</td>
<td>
<div class="inputRangeDiv">
<input class="inputRangeInputSlilder"
ng-init="skillScoreForm.skill[feedBack.applicantSkillID] = feedBack.rating"
ng-model="skillScoreForm.skill[feedBack.applicantSkillID]"
value="0"
oninput="skillOutput.value = skillInput.value"
id='skillInput' type="range"
min="0" max="5" ng-disabled="true" />

</div>
</td>
<td>
<div class="inlineFlex">
<output id="skillOutput" class="output">{{feedBack.rating}}</output>
<p class="applicantCutoffOutputSufixModalTable">/5</p>
</div>
</td>
</tr>
</tbody>

我怎样才能做到这一点,我认为我确信我需要使用两个ng-repeats,一个用于applicantInterviewerName,一个用于skills > 但不知道如何实现它。?

最佳答案

试试这个:

var obj = {
"batman": [{
"applicantSkillID": "htl2",
"rating": 3,
"applicantInterviewerID": "usr1",
"applicantInterviewerName": "batman",
"applicantSkillName": "HTML"
},
{
"applicantSkillID": "cs43",
"rating": 5,
"applicantInterviewerID": "usr1",
"applicantInterviewerName": "batman",
"applicantSkillName": "css"
}
],

"Superman": [{
"applicantSkillID": "ht12",
"rating": 3,
"applicantInterviewerID": "usr2",
"applicantInterviewerName": "Superman",
"applicantSkillName": "HTML"
},
{
"applicantSkillID": "cs43",
"rating": 3,
"applicantInterviewerID": "usr2",
"applicantInterviewerName": "Superman",
"applicantSkillName": "css"
}
]
};

function MyCtrl($scope) {
$scope.items = obj;
}
<script src="https://ajax.googleapis.com/ajax/libs/angularjs/1.2.23/angular.min.js"></script>
<div ng-app ng-controller="MyCtrl">
<div ng-repeat="(key,value) in items">
<div ng-repeat="data in items[key]">
<span>Name : </span>{{data.applicantInterviewerName}} , <span>Rating : </span>{{data.rating}}
</div>
</div>
</div>

关于javascript - 如何循环遍历angularjs中的对象数组,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/50778777/

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