部分更新交易中的多个小孩 [英] Partial update to more than one child in transaction

查看:110
本文介绍了部分更新交易中的多个小孩的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

要写入一个对象,需要使用 .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屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆