【问题标题】:I want to update the specific fields in the firebase by using like a SQL WHERE我想通过使用 SQL WHERE 来更新 firebase 中的特定字段
【发布时间】:2017-01-11 01:59:20
【问题描述】:

所以我有这个json数据

"User" : 
[{
    "Description" : "I loved to travel especially to countries such as Japan, Malaysia and Singapore",
    "FirstName" : "Josh",
    "LastName" : "Soh",
    "UserID" : "123"
}]

我想更新 FirstName 和 LastName 的字段,但我似乎无法更新。

我想做一些类似 UPDATE User WHERE UserID = 123 的事情

   $scope.edit = function (username,firstname,lastname) {
     var postData = {
            FirstName:firstname,
            LastName:lastname
        };


        var query = firebase.database().ref().child('User').push().key;

        console.log(query.toString());

        var updates = {};
        updates['/User/0/' + query] = postData;

        firebase.database().ref().update(updates);
}

【问题讨论】:

  • 你确定你在firebase中的数据结构吗?在firebase中它应该是一个json对象并且我上次检查时不支持数组结构。

标签: angularjs json ionic-framework


【解决方案1】:

如下所示修改您的 JSON 数据

{
    "user" : {
        "2p4OmQqCdCbZzUMLC2BhMJK83jU2" : {
            "Description" : "I loved to travel especially to countries such as Japan, Malaysia and Singapore",
            "FirstName" : "Josh",
            "LastName" : "Soh"
        }
    }
}

然后要更新您的数据,您可以使用以下代码。

firebase.database().ref('user/' + user.uid).update({
    "Description": "I loved to travel especially to countries such as Japan, Malaysia and Singapore",
    "FirstName": "Josh",
    "LastName": "Soh"
});

【讨论】:

    猜你喜欢
    • 2017-11-30
    • 1970-01-01
    • 2018-12-29
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2019-03-12
    • 2021-12-05
    相关资源
    最近更新 更多