部分更新交易中的多个小孩 [英] Partial update to more than one child in transaction
问题描述
.set()
,并且更新一个子对象(或者一些子对象) code> .update()。 是否有交易更新设施?
例如,我有一个对象: {person:{name:'name',address:'address',age:'age}}
。我想用一个事务来更新 age
和地址
,但是保留 name
>完整。
我不认为这样的函数存在。但是你可以通过复制更新函数中的所有更新的属性来自动生成一些东西,这些属性被传递给 transaction
。
var personRef = new Firebase('https://myapp.firebaseio.com/person1');
var update = {address:'10 downing street',age:42};
personRef.transaction(function)(person){
for(var prop in update)person [prop] = update [prop];
return person;
});
To write to an object, one uses .set()
, and to update a child object (or a number of child objects) leaving other children untouched you use .update()
.
Is there an update facility with transactions?
Example, I have an object: {person:{name:'name',address:'address',age:'age}}
. I want to use a transaction to just update age
and address
but leave name
intact.
I don't think such a function exists. But you could roll something yourself, by copying all updated properties in the update function that you pass into transaction
.
var personRef = new Firebase('https://myapp.firebaseio.com/person1');
var update = { address: '10 downing street', age: 42 };
personRef.transaction(function(person) {
for (var prop in update) person[prop] = update[prop];
return person;
});
这篇关于部分更新交易中的多个小孩的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!