gpt4 book ai didi

arrays - $firebaseArray 中的 For 循环

转载 作者:行者123 更新时间:2023-12-02 11:38:36 24 4
gpt4 key购买 nike

我发现了一些类似的主题,但其中大多数已经过时了,因为我使用的是 Angularfire 1.1.1。

我有一个 AngularJS 应用程序在 Google map 上创建标记。数据存储在外部 JSON 文件中,当我将其转换为数组时,它工作得很好。当我将数据放入 firebase 数据库时,它停止工作。带有数据的 ng 指令工作得很好,但是当在 js 代码中访问数组数据时,它实际上不起作用。

    app.controller('MapCtrl', ['$scope', '$firebaseArray', function($scope, $firebaseArray){

var ref = new Firebase("https://radiant-inferno-6439.firebaseio.com/tracks");
var syncObject = $firebaseArray(ref);
...

使用旧的离线 JSON 版本记录同步对象如下所示:

    [Object, Object, Object]
0: Object
1: Object
2: Object
length: 3
__proto__: Array[0]

但现在看起来像这样:

    []
0: Object
1: Object
2: Object
$$added: () { [native code] }
$$error: () { [native code] }
$$getKey: () { [native code] }
$$moved: () { [native code] }
$$notify: () { [native code] }
$$process: () { [native code] }
$$removed: () { [native code] }
$$updated: () { [native code] }
$add: () { [native code] }
$destroy: () { [native code] }
$getRecord: () { [native code] }
$indexFor: () { [native code] }
$keyAt: () { [native code] }
$loaded: () { [native code] }
$ref: () { [native code] }
$remove: () { [native code] }
$save: () { [native code] }
$watch: () { [native code] }
length: 3
__proto__: Array[0]

为什么会这样?当我打印数组的长度时,它显示为 0。我尝试了 $loaded 函数,但它没有影响。

    syncObject.$loaded().then(function(syncObject) {
console.log(syncObject.length);
});

我也无法访问数组的属性,因此无法循环遍历它。

最佳答案

看起来 $loaded() 方法不起作用。我在加载数据和执行其他操作之间添加了 2 秒超时,因此它开始工作。

关于arrays - $firebaseArray 中的 For 循环,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/30758243/

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