NG-重复:一个项目 - 唯一来源 [英] ng-repeat: One-item-only source
问题描述
这是我的code:
app.js
$ http.get(http://angularjs.uum.my/tt.json)
.success(功能(响应){$ scope.scrollItems =响应;});$ http.get(http://angularjs.uum.my/tt2.json)
.success(功能(响应){$ scope.scrollItems2 =响应;});
tt.json - 只有1元
tt2.json - 有两个2元
<醇开始=2>问题是与页面没有。 1,其中只有一个元素存在,则该页面呈现空列表重复次数x个(其中x等于子元素的数量)
这是已知的bug?
如何,如果元件的数目是未知的事先到显影剂解决这个问题?
请帮忙,感谢您的时间。
这是不是一个错误,你的第一个JSON是
{namakursus:约翰,pensyarah:李四,叶:星爷}
和第二个是
[
{namakursus:约翰,pensyarah:李四,叶:星爷},
{namakursus:John2,pensyarah:DOE2,叶:yeh2}
]
,这意味着第一个不是数组,故reapiting一个目的
如果你想获得相同的行为你的JSON应该和阵列仅1元,而不是一个单一的对象
[{namakursus:约翰,pensyarah:李四,叶:星爷}]
This is my code:
app.js
$http.get("http://angularjs.uum.my/tt.json")
.success(function(response) {$scope.scrollItems = response;});
$http.get("http://angularjs.uum.my/tt2.json")
.success(function(response) {$scope.scrollItems2 = response;});
tt.json - have only 1 element
tt2.json - have two 2 elements
The problem is with page no. 1, where only one element exist, the page rendered empty list repeating x number of times (where x equal to number of child elements)
Is this known bug? How to solve this problem if the number of elements is unknown beforehand to the developer?
Please help, thanks for your time.
That is not a bug, your first json is
{"namakursus":"John", "pensyarah":"Doe", "yeh":"yeh"}
and the second one is
[
{"namakursus":"John", "pensyarah":"Doe", "yeh":"yeh"},
{"namakursus":"John2", "pensyarah":"Doe2", "yeh":"yeh2"}
]
this means the first one is not an array, so it is reapiting an object
if you want to get the same behavior your json should be and array with only 1 element, not an single object
[{"namakursus":"John", "pensyarah":"Doe", "yeh":"yeh"}]
这篇关于NG-重复:一个项目 - 唯一来源的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!