【问题标题】:I want to get child key of object in angular2我想在angular2中获取对象的子键
【发布时间】:2017-08-21 19:57:30
【问题描述】:

在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,
            });
        }
    });
}

【问题讨论】:

  • 我听不懂你想说什么?
  • 是的,我只想在对象推送后更新键
  • 看图片我想得到education_qualification里面的钥匙

标签: angular firebase firebase-realtime-database


【解决方案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,
            });
        }
    });
}

【讨论】:

    猜你喜欢
    • 2020-10-30
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2016-05-20
    • 1970-01-01
    • 2021-09-10
    • 2020-08-28
    相关资源
    最近更新 更多