来自以下JSON片段的HI:
"comments":{
"count":2,
"data":[
{
"created_time":"1436046658",
"text":"Omg!!!! \u00bf!Pediste fondue?!",
"from":{
"username":"shanlynch",
"profile_picture":"https:\/\/instagramimages-a.akamaihd.net\/profiles\/profile_3904583_75sq_1379476264.jpg",
"id":"3904583",
"full_name":"shanlynch"
},
"id":"1021955900254028526"
},
{
"created_time":"1436049741",
"text":"Jajaa en el verano no hay fondue \ud83d\ude2f",
"from":{
"username":"elisamb9",
"profile_picture":"https:\/\/igcdn-photos-g-a.akamaihd.net\/hphotos-ak-xfa1\/t51.2885-19\/10852622_602060126561478_497106753_a.jpg",
"id":"209354191",
"full_name":""
},
"id":"1021981758431789771"
}
]
},
我想检索"文字"来自用户名的值" shanlynch"在ng-repeat循环中使用Angular,但不知道我该如何处理它。
我知道如何做这个基本的,但不确定如上:
示例:
"images":{
"low_resolution":{
"url":"https:\/\/scontent.cdninstagram.com\/hphotos-xaf1\/t51.2885-15\/s320x320\/e15\/11385601_1616392095286197_1575756416_n.jpg",
"width":320,
"height":320
}
}
Angular ng-repeat loop:
<li ng-repeat="p in pics">
<a href="#" target="_blank"><img ng-src="{{p.images.low_resolution.url}}" /></a>
</li>
答案 0 :(得分:0)
假设你有
$scope.comments; //Your JSON (content inside data)
你可以做到
<li ng-repeat="comment in comments">
<span ng-if="comment.from.username === 'shanlynch'">{{comment.text}}</span>
</li>
答案 1 :(得分:0)
在$ scope变量中包含所需的数据数组
var jsonData; //Put your JSON data in it
$scope.dataArr = jsonData.comments.data;
现在,您可以这样做,遍历数据对象中的所有数据对象(名为&#34; dat&#34;以避免混淆),并选择正确的数据对象。
<li ng-repeat="dat in dataArr">
<span ng-if="dat.from.username === 'shanlynch'">{{dat.text}}</span>
</li>
希望它有所帮助。
答案 2 :(得分:0)
btw你的json有效吗?请在http://jsonlint.com/
验证json如果它的有效JSON,那么下面的代码应该可以工作
<li ng-repeat="comment in comments.data">
<span ng-if="comment.from.username === 'shanlynch'">{{comment.text}}</span>
</li>