如何从另一个对象获取对象属性? Firebase + Vue

时间:2019-07-16 12:56:15

标签: javascript firebase vue.js firebase-realtime-database

Firebase中的对象很少:userattributesattributesValues

User具有一个名为attributes的属性,其值位于attributes对象中。

因此,如果对象user如下所示:

"user': {
    "name": "John"
    "attributes": {
        "0": "2",
    }
}

attributes对象看起来像这样:

"attributes": {
    "id": "0",
    "lastName": "Doe"
}

attributesValues对象如下:

"attributesValues": [
    "valueOne|valueTwo|valueThree|valueFour|valueFive",
     "typeOne|typeTwo|typeThree|typeFour|typeFive",
     "numberOne|numberTwo|numberThree|numberFour|numberFive",
     "addressOne|addressTwo|addressThree|addressFour|addressFive"
    ]}

如何显示用户的姓氏? user.attributes.[0]不起作用。

这是我的firebase文件:     从“ firebase”导入{initializeApp}

const app = initializeApp({
    apiKey: 'apiKey',
    authDomain: 'projectId.firebaseapp.com',
    databaseURL: 'https://projectId.firebaseio.com',
    projectId: 'projectId',
    storageBucket: '',
    messagingSenderId: 'messagingId',
    appId: 'appId'
})

export const db = app.database()
export const usersRed = db.ref('users')
export const attributesRef = db.ref('attributes')
export const attributesValuesRef = db.ref('attributesValues')

0 个答案:

没有答案