我是Polymer新手,我试图使用Firebase文档组件保存用户数据。Polymerfire TypeError
下面是相关的代码片段:
组件初始化:
<firebase-document id="document" app-name="nameoftheapp"
path="[[userDataPath]]" data="{{userData}}">
</firebase-document>
和JavaScript部分:
Polymer({
is: 'registration-view',
properties: {
userData: Object,
userDataPath: {
type: String,
notify: true
}
},
debugFunction: function() {
user = this.domHost.user;
this.userDataPath = '/users/' + user.uid;
this.userData.firstName = "fname";
this.userData.lastName = "lname";
console.log(user);
console.log(this.userDataPath);
this.$.document.save(this.userDataPath).then(function() {
console.log("success");
});
},
......
当我调用调试功能我得到的
Uncaught (in promise) TypeError: c[b] is not a function(…).
堆栈跟踪:
1) debugFunction @ registration-view.html:106
2) save @ firebase-document.html:82
3) (anonymous function) @ firebase-document.html:93
4) c @ firebase-app.js:formatted:939
的误差在最小火力-app.js文件异常,所以我不是从很聪明。一切都希望能够正确配置。用户身份验证工作正常,应用程序名称也很好(如果它不是应用程序未初始化错误将被抛出)。
我试图模拟数据库中的数据,并且firebase-document不加载它们。我设置了数据库规则,以便数据公开以消除潜在的授权问题,但它没有帮助。
{
"rules": {
// ".read": "auth != null",
".read": true,
// ".write": "auth != null"
".write": true
}
}
尝试2:
我发现another way如何保存数据,这里是代码:
<firebase-document id="document" app-name="doctor-appointment-system" log>
</firebase-document>
JavaScript部分:
debugFunction: function() {
this.$.document.path = null;
this.$.document.data = {
'firstName': this.$.fninput.value,
'lastName': this.$.lninput.value
};
console.log('users/' + this.domHost.user.uid);
this.$.document.save('users', this.domHost.user.uid);
},
有了这个设置我收到另一个错误。下面是从控制台输出:
users/Z5uAEYO2S1g2JYClpkk1Vtw130i2
app-storage-behavior.html:350 Setting Firebase value at users/Z5uAEYO2S1g2JYClpkk1Vtw130i2 to Object {firstName: "", lastName: ""}
firebase-database-behavior.html:61 Uncaught (in promise) TypeError: Cannot read property 'ref' of undefined(…)_setFirebaseValue
它未能在火力,数据库behaviour.html以下行:
var result = this.db.ref(path).set(leaf ? value.$val : value);
它看起来像有一些问题与配置,但认证工作正常所以我无能为力。
我被困在这一个,所以任何帮助将不胜感激。
谢谢,扬
我想'''.save(this.userDataPath)'''现在的问题是,你无法更新用户数据/ UID到新位置的用户/ UID /随机key –
谢谢为提示。你说得对,路径有问题。但是,如果我创建的数据(数据库目前是空的),我没有随机密钥,我不知道如何解决它。我认为Firebase应该自行生成密钥。那么我该如何告诉它这样做呢?非常感谢 –
https://github.com/firebase/polymerfire/blob/master/firebase-document.html#L81看这里save()自动为你创建随机密钥 –