迭代angularjs中对象中的属性列表
I have this object with arrays:
我有这个对象与数组:
"{
"Drivers":[
{
"Id":"41ba341a-e50f-4878-b55e-6c96ef5027b0",
"FirstName":"John",
"LastName":"David",
"MiddleName":"Smity",
"Party":{
"Id":"12rtb67-fa45-4e77-998c-123fgyh764",
"Name":"The Smith Family",
"CustomerId":"01d84752-ad12-4dfa-af63-65d12052a161"
}
},
{
"Id":"f37ff0c7-294d-43d1-a790-11af1f6f3e91",
"FirstName":"John",
"LastName":"Smith",
"MiddleName":"David",
"Party":{
"Id":"f2a82558-fa45-4e77-998c-29160f30f9f6",
"Name":"The Smith Family",
"CustomerId":"01d84752-ad12-4dfa-af63-65d12052a161"
}
}
]
}"
I want to iterate through the Drivers objects and display the values in angularjs foreach.
我想遍历Drivers对象并在angularjs foreach中显示值。
This is what I'm trying:
这就是我正在尝试的:
<table data-ng-controller="DriverController">
<thead>
<tr>
<th>Name</th>
</tr>
</thead>
<tbody data-ng-repeat="driver in Drivers.Drivers">
<tr>
<td>{{driver.FirstName}}</td>
</tr>
</tbody>
</table>
it didn't help.
它没有帮助。
I also tried:
我也尝试过:
<table data-ng-controller="DriverController">
<thead>
<tr>
<th>Name</th>
</tr>
</thead>
<tbody data-ng-repeat="driver in Drivers">
<tr>
<td>{{driver.FirstName}}</td>
</tr>
</tbody>
</table>
But I got the same result, no data shown on the screen.
但我得到了相同的结果,屏幕上没有显示数据。
Any idea how can I solve this and iterate through the properties of the array and display the results in a table as I'm trying in the example?
任何想法如何解决这个问题并迭代数组的属性并在表格中显示结果,因为我正在尝试示例?
Thanks
2 个解决方案
#1
0
Your JSON was a string in the example. If that is how you are receiving it from the server, you will need to parse it. Barring that, your code works in this plunker: http://plnkr.co/edit/x2IJRCUUTqpYnombadzn?p=preview
您的JSON是示例中的字符串。如果这是您从服务器接收它的方式,则需要解析它。除此之外,您的代码可以在这个插件中工作:http://plnkr.co/edit/x2IJRCUUTqpYnombadzn?p = preview
<table data-ng-controller="DriverController">
<thead>
<tr>
<th>Name</th>
</tr>
</thead>
<tbody data-ng-repeat="driver in drivers.Drivers">
<tr>
<td>{{driver.FirstName}}</td>
</tr>
</tbody>
</table>
$scope.drivers = {
"Drivers":[
{
"Id":"41ba341a-e50f-4878-b55e-6c96ef5027b0",
"FirstName":"John",
"LastName":"David",
"MiddleName":"Smity",
"Party":{
"Id":"12rtb67-fa45-4e77-998c-123fgyh764",
"Name":"The Smith Family",
"CustomerId":"01d84752-ad12-4dfa-af63-65d12052a161"
}
},
{
"Id":"f37ff0c7-294d-43d1-a790-11af1f6f3e91",
"FirstName":"John",
"LastName":"Smith",
"MiddleName":"David",
"Party":{
"Id":"f2a82558-fa45-4e77-998c-29160f30f9f6",
"Name":"The Smith Family",
"CustomerId":"01d84752-ad12-4dfa-af63-65d12052a161"
}
}
]
}
更多相关文章
- 如何使用变量创建数组?
- 高德地图api接口poi检索示例----并在信息框显示经纬度
- 推json敲出可观察的数组
- 从占用转义字符的字符数组创建字符串
- 如何获取knockoutjs可观察数组的下一个元素?
- 显示json数组中的所有项目
- 图表。js数据数组使用PHP, MySQL。如何从JSON数组定义数据源?
- 将JavaScript对象转换为要插入关系数据库的数组
- javascript数组和对象是否有设置顺序?