【问题标题】:How to get the new key pushed on firebase?如何在firebase上推送新密钥?
【发布时间】:2019-05-09 23:59:01
【问题描述】:

亲爱的,

我不知道如何让他在 firebase 中推送新密钥。 这是我的简单示例代码:

FirebaseDatabase.instance.reference().child('mychild').push().set(
            <String, String>{
              'hello': 'world',
            });

我怎样才能得到这个元素的键被推送?

谢谢

【问题讨论】:

    标签: firebase-realtime-database dart flutter


    【解决方案1】:

    你可以试试这个:

    DatabaseReference rootRef = FirebaseDatabase.instance.reference(); 
    String newkey = rootRef.child('mychild').push().key;
    rootRef.child('mychild').child(newKey).set(<String, String>{'hello': 'world',});
    

    【讨论】:

    • 谢谢@florex 正确的代码是:code DatabaseReference rootRef = FirebaseDatabase.instance.reference(); String newkey=rootRef.reference().child('mychild').push().key; print (newkey); rootRef.child('mychild').child(newkey).set( &lt;String, String&gt;{ 'hello': 'world', }); 谢谢:)
    猜你喜欢
    • 1970-01-01
    • 2019-01-28
    • 1970-01-01
    • 2023-04-05
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2019-06-04
    • 2019-03-29
    相关资源
    最近更新 更多