[英]Angularjs multiple arrays with json
好吧,今天我有一个新问题。 我正在尝试采用此json的多个数组。
[{“ _id”:“ 541200a79fb6706de9164063”,“ index”:0,“ guid”:“ 403d5692-0f07-40e6-84f5-32cdee137127”,“ isActive”:true,“ school”:“ BOILICON”,“ address”: “ 532 Everit Street,威廉姆森,肯塔基州197”,“注册”:“ 2014年3月24日,星期一,凌晨4:46”,“教授”:[{“ id”:0,“ name”:{“ first”: “ Mclean”,“ last”:“ Robertson”},“ email”:“ mclean.robertson@undefined.com”,“ age”:36,“ phone”:“ +1(946)436-2567”,“ coursePrice “:” $ 4,882.28“,” favoriteParadigm“:” funcional“}]}
好吧,我尝试在html代码上这样做:
$<div ng-controller="studentsController">
<table>
<tr ng-repeat= "student in data.students">
<td>{{student.index}}</td>
<td>{{student.guid}}</td>
<td>{{student.isActive}}</td>
<td>{{student.school}}</td>
<td>{{student.address}}</td>
<td ng-repeat="prof in data.students.professor">
email: {{prof.email}}
</td>
</tr>
</table>
</div>$
但这对我不起作用。 谁能帮我吗?
在ng-repeat中,您具有不同的范围,并且可以直接访问当前项目。 所以改变
<td ng-repeat="prof in data.students.professor">
对此:
<td ng-repeat="prof in student.professor">
email: {{prof.email}}
</td>
将prof in data.students.professor
更改prof in data.students.professor
中的prof in students.professor
因为您之前已经student in data.students
定义了student in data.students
因此student
将student in data.students
内部包含professor
详细信息
试试看
<div ng-app='myApp' ng-controller="studentsController">
<table border="1">
<tr ng-repeat="student in students">
<td>{{student.index}}</td>
<td>{{student.guid}}</td>
<td>{{student.isActive}}</td>
<td>{{student.school}}</td>
<td>{{student.address}}</td>
<td ng-repeat="prof in student.professor">email: {{prof.email}}</td>
</tr>
</table>
</div>
问题陈述中的几件事,
因此您的代码将如下所示:
HTML:
<div ng-app>
<table ng-controller="test">
<tr ng-repeat="student in data.students track by $index">
<td>{{student.index}}</td>
<td>{{student.guid}}</td>
<td>{{student.isActive}}</td>
<td>{{student.school}}</td>
<td>{{student.address}}</td>
<td ng-repeat="prof in student.professor track by $index">email: {{prof.email}}</td>
</tr>
</table>
</div>
JS:
function test($scope) {
$scope.data = {};
var students = '[ { "_id" : "541200a79fb6706de9164063" , "index" : 0 , "guid" : "403d5692-0f07-40e6-84f5-32cdee137127" , "isActive" : true , "school" : "BOILICON" , "address" : "532 Everit Street, Williamson, Kentucky, 197" , "registered" : "Monday, March 24, 2014 4:46 AM" , "professor" : [ { "id" : 0 , "name" : { "first" : "Mclean" , "last" : "Robertson"} , "email" : "mclean.robertson@undefined.com" , "age" : 36 , "phone" : "+1 (946) 436-2567" , "coursePrice" : "$4,882.28" , "favoriteParadigm" : "funcional"} ]}]';
$scope.data.students = JSON.parse(students);
}
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.