1

使用 firebase-element 时,什么被认为是最有效的方法?

  1. 每个位置的新 firebase-element。

  2. 使用 for 循环。

每个位置的新 firebase-element

...
<firebase-element location="https://YOUR-FIREBASE.firebaseio.com/users"></firebase-element>
<firebase-element location="https://YOUR-FIREBASE.firebaseio.com/products"></firebase-element>
<firebase-element location="https://YOUR-FIREBASE.firebaseio.com/info"></firebase-element>
...

使用 for 循环。

...
<firebase-login location="https://YOUR-FIREBASE.firebaseio.com/" user="{{fbUser}}"></firebase-login>
<firebase-element location="https://YOUR-FIREBASE.firebaseio.com/" data="{{fbData}}" dataReady="{{dataReady}}"></firebase-element>
...
Polymer({
    data: null,
    user: null,

    observe: {
        'fbData': 'syncData',
        'fbUser dataReady': 'syncUser'
    },

    syncData: function() {
        if(this.data.products !== this.fbData.products) {
            this.products = this.fbData.products;
        }
    },

    syncUser: function() {
        if(this.fbUser && this.dataReady) {
            for(var user in this.fbData.users) {
                if(this.fbData.users[user] === this.fbUser.uid) {
                    this.user = this.fbData.users[user];
                } else {
                    this.user = null;  
                }               
            }
        }            
    }
});
4

0 回答 0