gpt4 book ai didi

angularjs - ng-repeat 似乎不起作用

转载 作者:行者123 更新时间:2023-12-02 01:55:37 25 4
gpt4 key购买 nike

我正在尝试从名为“集合”的数组中提取所有项目。当我在 html 中输入调用时,我只看到页面上数组中第一项的完整代码。我试图只拉入“edm.preview”,这是该项目的图像。我正在使用 Angular Firebase 和一个名为 Europeana 的 api 。我的应用程序允许用户搜索并选择他们喜欢的图像并将其保存给特定用户。

这是js:

  $scope.users = fbutil.syncArray('users');

$scope.users.currentUser.collections = fbutil.syncArray('collections');
$scope.addSomething = function (something) {
var ref = fbutil.ref('users');
ref.child($rootScope.currentUser.uid).child('collections').push(something);
}
$scope.addSomething = function(item) {
if( newColItem ) {
// push a message to the end of the array
$scope.collections.$add(newColItem)
// display any errors
.catch(alert);
}
};

和 html:

<ul id="collections" ng-repeat="item in collections">
<li ng-repeat="item in collections">{{item.edmPreview}}</li>
</ul>

最佳答案

首先,删除外部 ng-repeat 。您只想添加 ng-repeat指向正在重复的元素的指令,在本例中为 <li> .

其次,从你的 AngularJS 代码来看,你似乎想循环 users.currentUser.collections不仅仅是collections :

 <ul id="collections">
<li ng-repeat="item in users.currentUser.collections">{{item.edmPreview}}</li>
</ul>

第三,您定义函数 $scope.addSomething在 JavaScript 代码中两次。现在,第二个函数定义(顺便说一句,也应该更改为更新 $scope.users.currentUser.collections)将完全取代第一个。

关于angularjs - ng-repeat 似乎不起作用,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/26218310/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com