我是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()自動爲你創建隨機密鑰 –