如何在angularjs中循环遍历对象数组

时间:2018-06-09 21:40:21

标签: javascript arrays angularjs json angularjs-ng-repeat

我有一个这样的对象:

{
"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明智(蝙蝠侠评级,超人评级等)。

只有一个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使用一个但不知道如何实现它。 ?

1 个答案:

答案 0 :(得分:1)

试试这个:

&#13;
&#13;
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;
}
&#13;
<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>
&#13;
&#13;
&#13;