Firebase.push失败:第一个参数包含无效键($$ hashKey)

use*_*800 17 angularjs firebase

我最近开始学习AngularJS + Firebase.我正在尝试在我的firebase中写一个这样的对象:

{
    title: "Personal Information",
    say: [
        [{ "eng": "What's", "ukr": "?? ?" }, { "eng": "your", "ukr": "????" }, { "eng": "surname?", "ukr": "?????????" }],
        [{ "eng": "Smith", "ukr": "????" }],
        [{ "eng": "What's", "ukr": "?? ?" }, { "eng": "your", "ukr": "????" }, { "eng": "first", "ukr": "?????" }, { "eng": "name?", "ukr": "??'??(?? ???????)" }]
    ]
}
Run Code Online (Sandbox Code Playgroud)

有线:

lessondata.add($scope.topic);
Run Code Online (Sandbox Code Playgroud)

'lessondata'是使用angularFireCollection()和$ scope.topic创建的服务 - 绑定到我的UI的对象.但是得到了以下错误: Firebase.push失败:第一个参数在属性'say.0.0'中包含无效键($$ hashKey).键必须是非空字符串,不能包含".","#","$","/","["或"]"


据我所知,Firebase不允许使用0作为键,即使它是附加数组中的键,其中零键是自然的.那么我应该在一些硬编码实例中更改我的对象结构还是我想念一些东西?提前致谢!

ben*_*ich 25

编辑:正如Anant在评论中指出的那样,在Angular的最新稳定版本(1.0.7 atm)中,您可以使用angular.copy(obj)删除$$hashkey属性.

就像迈克尔所说,'$$ hashKey'中的'$'是个问题.Angular $$hashKey在幕后创建属性(请参阅此处:https://groups.google.com/forum/#!topic / angular/pI0IgNHKjxw).通过做类似的事情,我已经解决了这个问题myRef.push(angular.fromJson(angular.toJson(myAngularObject))).

  • angular.copy()也应该摆脱$$ hashKey属性. (6认同)

Mic*_*uer 6

问题是"$ hashKey"中的$,而不是0允许.