我是角度js的新手,我试图理解这一点,但仍然不明白为什么它没有显示结果。我正在尝试获取entry_date
和remarks
。这是我的数组示例: -
0: {
name: "James",
student_branch: {
0: {
entry_date: "13 Dec 2016",
remarks: "Naughty"
},
1: {
entry_date: "13 Dec 2017",
remarks: "Nice"
}
}
class: "Gems"
}
1: {
name: "Admiral",
student_branch: {
0: {
entry_date: "13 Dec 2016",
remarks: "Naughty"
},
1: {
entry_date: "13 Dec 2017",
remarks: "Naughty"
}
}
class: "Gold"
}
我尝试了这个,但它不起作用,上面显示的数组位于studentDetails
,
<tr ng-repeat="customer in studentDetails">
<td ng-repeat="(key, value) in studentHeader">
<!-- Ignore this line -->
<div ng-repeat="item in customer.student_branch track by $index">
<span ng-repeat="value in item track by $index">{{value.entry_date}}</span>
<span ng-repeat="value in item track by $index">{{value.remarks}}</span>
</div>
</td>
</tr>
答案 0 :(得分:-1)
您似乎正在使用ng-repeat
,因为它不太合适。
当您使用ng-repeat="item in customer.student_branch track by $index"
时,item
变量将包含每次迭代的此类对象:
{ entry_date: "13 Dec 2016", remarks: "Naughty" }
然后,当您使用嵌套ng-repeat="value in item track by $index"
时,value
- 变量实际上将包含值
"13 Dec 2016"
and
"Naughty"
所以当你尝试使用例如value.entry_date
,它会返回undefined
,因为这实际上等同于调用"13 Dec 2016".entry_date
。因此,拥有最内部ng-repeat
是造成问题的原因。当你真正尝试迭代集合时,你应该只使用ng-repeat。
所以正确的代码应如下所示:
<tr ng-repeat="customer in studentDetails">
<td ng-repeat="(key, value) in studentHeader"><!-- Ignore this line -->
<div ng-repeat="item in customer.student_branch track by $index">
<span>{{item.entry_date}}</span>
<span>{{item.remarks}}</span>
</div>
</td>
</tr>
答案 1 :(得分:-1)
您需要进行一些更改,例如
@interface Superclass : NSObject
@end