【发布时间】:2017-04-08 23:04:03
【问题描述】:
我有一些 JSON 数据正在加载到一个列表中,该列表在所述数据中包含子列表。 JSON 数据是使用 get 调用从 API 中提取的
"pet": [
{
"options": {
"option": [
{
"$t": "hasShots"
},
{
"$t": "altered"
},
{
"$t": "housetrained"
}
]
},
"status": {
"$t": "A"
},
"contact": {
"phone": {
"$t": "emails only please"
},
"state": {
"$t": "NC"
},
"address2": {
},
"email": {
"$t": "techmed1@netzero.net"
},
"city": {
"$t": "Charlotte"
},
"zip": {
"$t": "28226"
},
"fax": {
},
"address1": {
}
},
"age": {
"$t": "Senior"
},
"size": {
"$t": "M"
},
"media": {
"photos": {
"photo": [
{
"@size": "pnt",
"$t": "http:\/\/photos.petfinder.com\/photos\/pets\/36298811\/1\/?bust=1475677088&width=60&-pnt.jpg",
"@id": "1"
},
{
"@size": "fpm",
"$t": "http:\/\/photos.petfinder.com\/photos\/pets\/36298811\/1\/?bust=1475677088&width=95&-fpm.jpg",
"@id": "1"
},
{
"@size": "x",
"$t": "http:\/\/photos.petfinder.com\/photos\/pets\/36298811\/1\/?bust=1475677088&width=500&-x.jpg",
"@id": "1"
},
{
"@size": "pn",
"$t": "http:\/\/photos.petfinder.com\/photos\/pets\/36298811\/1\/?bust=1475677088&width=300&-pn.jpg",
"@id": "1"
},
{
"@size": "t",
"$t": "http:\/\/photos.petfinder.com\/photos\/pets\/36298811\/1\/?bust=1475677088&width=50&-t.jpg",
"@id": "1"
},
{
"@size": "pnt",
"$t": "http:\/\/photos.petfinder.com\/photos\/pets\/36298811\/2\/?bust=1475677088&width=60&-pnt.jpg",
"@id": "2"
},
{
"@size": "fpm",
"$t": "http:\/\/photos.petfinder.com\/photos\/pets\/36298811\/2\/?bust=1475677088&width=95&-fpm.jpg",
"@id": "2"
},
{
"@size": "x",
"$t": "http:\/\/photos.petfinder.com\/photos\/pets\/36298811\/2\/?bust=1475677088&width=500&-x.jpg",
"@id": "2"
},
{
"@size": "pn",
"$t": "http:\/\/photos.petfinder.com\/photos\/pets\/36298811\/2\/?bust=1475677088&width=300&-pn.jpg",
"@id": "2"
},
{
"@size": "t",
"$t": "http:\/\/photos.petfinder.com\/photos\/pets\/36298811\/2\/?bust=1475677088&width=50&-t.jpg",
"@id": "2"
},
{
"@size": "pnt",
"$t": "http:\/\/photos.petfinder.com\/photos\/pets\/36298811\/3\/?bust=1475677088&width=60&-pnt.jpg",
"@id": "3"
},
{
"@size": "fpm",
"$t": "http:\/\/photos.petfinder.com\/photos\/pets\/36298811\/3\/?bust=1475677088&width=95&-fpm.jpg",
"@id": "3"
},
{
"@size": "x",
"$t": "http:\/\/photos.petfinder.com\/photos\/pets\/36298811\/3\/?bust=1475677088&width=500&-x.jpg",
"@id": "3"
},
{
"@size": "pn",
"$t": "http:\/\/photos.petfinder.com\/photos\/pets\/36298811\/3\/?bust=1475677088&width=300&-pn.jpg",
"@id": "3"
},
{
"@size": "t",
"$t": "http:\/\/photos.petfinder.com\/photos\/pets\/36298811\/3\/?bust=1475677088&width=50&-t.jpg",
"@id": "3"
}
]
}
},
"id": {
"$t": "36298811"
},
"shelterPetId": {
"$t": "Domino"
},
"breeds": {
"breed": {
"$t": "Domestic Medium Hair"
}
},
"name": {
"$t": "Domino"
},
"sex": {
"$t": "M"
},
"description": {
"$t": "Domino is a sweet, talkative kitty with lots of purr-sonality. He never meets a stranger, and will let children carry him around in their arms. \nHe has tested positive for FIV, but we have had him in our rescue since 2009, and he has never had any health problems at all. He is neutered and up to date on vaccinations.We think he was born around 2005-2006. Must be an indoor only cat. He has had regular dental cleanings; last one was April of 2015. He would make a great companion for anyone who wants an affectionate kitty to love and care for."
},
"mix": {
"$t": "no"
},
"shelterId": {
"$t": "NC773"
},
"lastUpdate": {
"$t": "2017-03-15T12:37:11Z"
},
"animal": {
"$t": "Cat"
}
}
]
我的代码是
<ol><li ng-repeat="pet in pets | orderBy: 'name.$t'">
<div>{{pet.name.$t}} - {{pet.animal.$t}}</div>
<div ng-repeat="pic in pet.photo">{{pic.$t}}</div>
</li>
<ul></ul>
</ol>
和 pets = 上面的 JSON 数据。第一个 ng-repeat 工作正常,第二个嵌套在第一个内则不行。最初我将它作为 ng-src 放在 img 标签中,我认为它与 $sce 源代码保护有关,但这也不起作用,因此似乎并非如此
【问题讨论】:
-
你能更精确一点吗? “不起作用”是什么意思?你尝试了什么?你现在的结果是什么?你期望的结果是什么?
-
我只是在测试是否可以正确返回照片列表。最终我将拥有一个可以浏览的画廊,但我意识到我的阵列搞混了。
标签: angularjs json angularjs-ng-repeat