Angular.js - 嵌套JSON范围与角 [英] Angular.js - Nested JSON scope with Angular
本文介绍了Angular.js - 嵌套JSON范围与角的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
{
"imports": {
"imported": [
{
"date": "19/9/2014",
"item": [
{
"sn": "3366698",
"type": "Food",
"weight": "10tn."
},
{
"sn": "3366699",
"type": "Eqipment",
"weight": "20kg."
}
]
},
{
"date": "20/9/2014",
"item": [
{
"sn": "3366700",
"type": "Electronics",
"weight": "100pt."
},
{
"sn": "3366701",
"type": "Food",
"weight": "5tn."
}
]
}
]
}
}
我有这样的JSON,我不知道这是否是在正确的结构。我试图呈现每个项目类型(包括重复),如下面的$ .getJSON方法表头:
I have this json and I am not sure if it's in the right structure. I am trying to render each item type (duplicates included) as table header by the following $.getJSON method:
$scope.items = data.imports.item;
和HTML如下:
<table border="1" >
<thead>
<tr>
<th ng-repeat="item in items">{{item.type}}</th>
</tr>
</thead>
</table>
但我不能成功。我在做什么错了?
But I couldn't succeed. What am I doing wrong?
编辑: jsfiddler
推荐答案
您JSON北京时间坏了,在这里粘贴您的JSON:
http://jsonformatter.curiousconcept.com/
Your json ist broken, paste your json here: http://jsonformatter.curiousconcept.com/
您会看到data.imports.item将是不确定的。
You'll see that data.imports.item would be undefined.
正确的JSON访问将如下所示:
Correct JSON to access would look like:
{
"imports": {
"item": [
{
"sn": "3366698",
"type": "Food",
"weight": "10tn."
},
{
"sn": "3366699",
"type": "Eqipment",
"weight": "20kg."
}
]
}
}
后也访问您的数据:
Also access your data after:
<th ng-repeat="item in items">
{{item["type"]}}
</th>
这篇关于Angular.js - 嵌套JSON范围与角的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文