Vuefire: key of pushed item

Created on 29 Jan 2017  路  1Comment  路  Source: vuejs/vuefire

If I want to get the key of a pushed item I found I can do something like this:

someRef.push(newItem).then(function(result) {
  var key = result.path.o[1]
  // do something with key
})

Will the path.o property possibly change in future versions? Is there a better way to get the key of a newly pushed item that I'm missing?

question

Most helpful comment

You should use the return value of the push() call instead:

var ref = someRef.push(newItem);
var key = ref.key;
// do something with key

The path.o property is not an actual API and it just caused by minification and will certainly break in future versions. Nicely, the code above works synchronously and you don't actually have to wait for the push to finish before getting the key of the new ref.

>All comments

You should use the return value of the push() call instead:

var ref = someRef.push(newItem);
var key = ref.key;
// do something with key

The path.o property is not an actual API and it just caused by minification and will certainly break in future versions. Nicely, the code above works synchronously and you don't actually have to wait for the push to finish before getting the key of the new ref.

Was this page helpful?
0 / 5 - 0 ratings

Related issues

SonarBeserk picture SonarBeserk  路  4Comments

magicseth picture magicseth  路  6Comments

torfeld6 picture torfeld6  路  4Comments

calirails picture calirails  路  5Comments

amesas picture amesas  路  5Comments