我想在angular2中获取对象的子键

时间:2017-08-21 08:00:45

标签: angular firebase firebase-realtime-database

在education_qualification对象里面生成随机密钥我想得到那个密钥,怎么可能? 我试图更新该密钥,但我只获得了education_qualification而不是内部密钥。

create(model, bankDetails, currentAddress, permanentAddress, education) {
const obj = this.employees.push(model);
obj.update({
    id: obj.key,
    bank_details: bankDetails,
    current_address: currentAddress,
    permanent_address: permanentAddress,
},
    (error) => {
        const edu = obj.child('/education_qualification/');
        for (let i = 0; i <= education.length; i++) {
            edu.push(education[i]);
             edu.update({  
                  id: edu.key,
            });
        }
    });
}

I want key inside of education_qualification

1 个答案:

答案 0 :(得分:-1)

Push返回数据库引用。

Firebase push documentation

这意味着获取密钥,您可以执行以下操作:

create(model, bankDetails, currentAddress, permanentAddress, education) {
const obj = this.employees.push(model);
obj.update({
    id: obj.getKey(),
    bank_details: bankDetails,
    current_address: currentAddress,
    permanent_address: permanentAddress,
},
    (error) => {
        const edu = obj.child('/education_qualification/');
        for (let i = 0; i <= education.length; i++) {
            edu.push(education[i]);
             edu.update({  
                  id: edu.key,
            });
        }
    });
}