如何使用JavaScript在Firebase中插入/更新数据? [英] How to insert/update data in firebase using javascript?

查看:147
本文介绍了如何使用JavaScript在Firebase中插入/更新数据?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个Firebase数据库,其中的节点结构是这样。如何使用JavaScript从网页中插入/更新数据?我想分别在promo_ar,promo_en和promo_fr中插入数据。



我是Firebase的新手,我们将非常感谢您的帮助!

解决方案

您必须采用这种方式

  firebase.database()。ref('Promotions / promo_en')。set({{
desc_promo:value,
name_promo:value
});

请记住,使用set可以更新数据库节点的元素,另一方面,当执行这种类型的更新时,必须发送两个元素以在该节点内进行更新,如果省略任何元素,则将从您的基础中删除该元素,例如...

  firebase.database()。ref('Promotions / promo_en')。set({
desc_promo:value,

});

在这种情况下,仅desc_promo被更新,从而消除了其余的节点元素。 p>

就像您可以在这样的元素中插入新节点一样

  firebase.database()。ref('Promotions / promo_es')。set({
desc_promo:value,
name_promo:value

});

通过这种方式,我们将西班牙语添加到促销节点



AGGREGATE:



在主节点下可以有任意多个节点,请记住,如果要更新最终节点,它不会影响较高的节点,但是较高的节点会影响较低的节点,例如

  firebase.database()。ref('Promotions / promo_es / exchange')。set(
{
desc_promo:value,
name_promo:value
}
);

促销
| _promo_es
| _desc_promo:价值
| _name_promo:价值
| _>交换
| _> desc_promo:值//<-这已更新或创建
| _> name_promo:值//<-这已更新或创建

现在,如果您在不包含子节点的情况下编辑 Promotions / promo_es 节点,这些将被删除,您可以执行您认为方便的测试在firebase中完善在系统中使用的方法


I have a firebase database where a node structure is like this.How do I insert/update data from a web page using javascript? I want to insert data individually in promo_ar,promo_en and promo_fr.

I am new in firebase and the help will be much appreciated!

解决方案

You must do it this way

firebase.database().ref('Promotions/promo_en').set({
    desc_promo: value,
    name_promo: value
  });

Remember that using set, you update elements of a node of your database, on the other hand, when you perform this type of updates, you must send both elements to update within that node, if you omit any element, it is removed from your base, for example...

firebase.database().ref('Promotions/promo_en').set({
    desc_promo: value,

  });

In this case, only desc_promo is being updated, thus eliminating the rest of the node elements.

in the same way you can insert new nodes in an element like this

firebase.database().ref('Promotions/promo_es').set({
    desc_promo: value,
    name_promo: value

  });

in this way we add the Spanish language to the Promotions node

AGGREGATE:

you can have as many nodes as you want below a main node, remember that if you are going to update the final node, it does not affect the higher ones, but the higher node does affect the lower ones, for example

firebase.database().ref('Promotions/promo_es/exchange').set(
    { 
        desc_promo: value, 
        name_promo: value 
    }
);

Promotions
        |_>promo_es
                |_>desc_promo : value 
                |_>name_promo : value 
                |_>exchange
                        |_>desc_promo : value //<-this is updated or created
                        |_>name_promo : value //<- this is updated or created

now if you edit the Promotions / promo_es node without including its sub nodes, these will be eliminated, you can perform the tests that you deem convenient in firebase to polish the method to use in your system

这篇关于如何使用JavaScript在Firebase中插入/更新数据?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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