我可以获得刚刚添加的对象的密钥吗?
例如:
items.push(
{ ... }
).then(_ => console.log(key of the object));
我可以获得刚刚添加的对象的密钥吗?
例如:
items.push(
{ ... }
).then(_ => console.log(key of the object));
items.push(
{ ... }
).then(_ => console.log('Added item key is ', _.key));
请像这样尝试。
如果您的意思是 Firebase 3(AngularFire$firebaseArray
有一个$add
to replace push
),那么它返回一个也是“thenable”的引用,请查看Firebase 文档
因此,您key
甚至可以同步获取参考:
var thenableRef = dataRef.push({someKey: 'some value'});
var newItemKey = thenableRef.$key;
thenableRef.then(_ => console.log('There\'s my new key: %s', newItemKey));