【发布时间】:2014-08-20 09:54:18
【问题描述】:
如主题中所述,当我对第一个元素始终为空的事物使用 ng-repeat 时,会出现什么问题?我已经尝试了几种方法来摆脱这个问题,但似乎没有奏效。
我所有的 ng-repeat 数据都存储在 JSON 文件中,并且 JSON 文件将通过 $http 调用传递给作用域,如下所示:
$http.get('index.php?r=exploreComment/WS_getExploreComments&topic_id=' + topic_id).success(function(data){
$scope.comments = data;
console.log('Comment Loaded');
一切都正确加载,只是 ng-repeat 循环中的第一项始终为 null..
GET http://localhost/viralenz/resource/_explore/%7B%7Bphoto.image%7D%7D 404 (Not Found)
GET http://localhost/viralenz/resource/_explore/%7B%7Bimage.image%7D%7D 404 (Not Found)
GET http://localhost/viralenz/resource/_users/%7B%7Bcomment.user_id%7D%7D/avatar/%7B%7Bcomment.avatar%7D%7D 404 (Not Found)
我以为这只是 JSON 数据的错误,但后来我尝试了图像,也出现了同样的问题...我无法添加图像,所以我附上了一个链接...
http://i.stack.imgur.com/lsFDX.png
我做错了什么?
///// 编辑了更多细节 ////
这就是 ng-repeat 的样子
<div class="exploreCommentBlock" ng-repeat="comment in comments">
<table style="width: 100%">
<tr style="width: 100%">
<td style="width: 5%" rowspan="2" valign="top"><img
src="<?php echo UrlMgmt::getUserResourceUrl()?>{{comment.user_id}}/avatar/{{comment.avatar}}"
, style='height: 64px; width: 64px; border-radius: 5px;' /></td>
<td style="width: 70%"><span class="author_name">{{comment.username}}</span>
--AND--SO--ON--
这是 JSON 数据:
[{"comment_id":"92","user_id":"1","topic_id":"1","data":"lalalalalalaa","image_append":null,"rating":"1","datetime":"2014-08-19 13:03:58","username":"Kenny Yap","avatar":"14079353851"},
{"comment_id":"91","user_id":"1","topic_id":"1","data":"test blank post","image_append":null,"rating":"1","datetime":"2014-08-19 10:48:41","username":"Kenny Yap","avatar":"14079353851"},
{"comment_id":"28","user_id":"2","topic_id":"1","data":"test owner comment","image_append":null,"rating":"5","datetime":"2014-08-18 09:39:59","username":"Dummy User","avatar":"default_avatar.png"}]
【问题讨论】:
-
数据长什么样,ng-repeat长什么样?
-
@PSL 我已经添加了 ng-repeat 和 JSON 数据样本。谢谢
-
哪个字段显示为空?您是否没有在 html 中显示相关部分
标签: json angularjs angularjs-ng-repeat