Can we use Firebase update function for updating priority as well -


i updating properties of object in firebase using update method. part of update call, can update priority of object?

i have collection of objects stored in firebase. using javascript sdk interact data. whenever update property of object, set priority of object firebase.servervalue.timestamp constant.

now, want start storing priority of each object in property called updatedontimestampts defined on object. whenever update property update updatedontimestampts timestamp constant.

now problem is, unable find way call update function along priority (no updatewithpriority setwithpriority). if update updatedontimestampts , priority in 2 different operations using timestamp constant may (or will) end different values.

how can address this?

i know i'm way late on answer here, i'm coming across need similar , updatewithpriority doesn't exist (nor way view/edit priorities in forge).

you can include specially-named key, .priority in update , ought achieve desired effect.

the .priority key documented in firebase rest api, can used in other libraries.

so, in javascript, following work if wanted update priority (which, there setpriority that):

var fb = new firebase("http://a_firebase.firebaseio.com"); var ref = fb.child("/path/to/child"); var data = { ".priority": (new date()).gettime() } //timestamp, mentioned ref.update(data); 

if wanted change priority while you're updating other properties, had asked, include data want update:

var fb = new firebase("http://a_firebase.firebaseio.com"); var ref = fb.child("/path/to/child"); var data = {      "property1": "updated_val",     "property2": "updated_val2",     ".priority": (new date()).gettime(), //timestamp, mentioned } ref.update(data); 

edit: clear, update priority at location of child reference (i.e. /path/to/child) not priorities of individual children being updated (i.e. priorities of property1 , property2). if wanted include priority children being updated, , children leaf nodes (i.e. string, number, boolean), can use specially-named .value key in conjunction .priority key so.

the following example shows how update priority root location update occurring (i.e. path/to/child) both children being update (i.e. property1 , property2). obviously, selectively pick priorities update if didn't want update them all.

var fb = new firebase("http://a_firebase.firebaseio.com"); var ref = fb.child("/path/to/child"); var newpriority = (new date()).gettime(); //timestamp, mentioned var data = {      "property1": {".value": "updated_val", ".priority": newpriority},     "property2": {".value": "updated_val2", ".priority": newpriority},     ".priority": newpriority } ref.update(data); 

Comments

Popular posts from this blog

html - How to style widget with post count different than without post count -

How to remove text and logo OR add Overflow on Android ActionBar using AppCompat on API 8? -

javascript - storing input from prompt in array and displaying the array -