Skip to content
This repository was archived by the owner on Apr 4, 2023. It is now read-only.

Commit 1a69df3

Browse files
[Realtime DB] update data by key creates an array of chars instead of string #257
1 parent 9a44a82 commit 1a69df3

File tree

2 files changed

+17
-0
lines changed

2 files changed

+17
-0
lines changed

firebase.android.js

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1111,7 +1111,15 @@ firebase.setValue = function (path, val) {
11111111
firebase.update = function (path, val) {
11121112
return new Promise(function (resolve, reject) {
11131113
try {
1114+
if (typeof val == "object") {
11141115
firebase.instance.child(path).updateChildren(firebase.toHashMap(val));
1116+
} else {
1117+
var lastPartOfPath = path.lastIndexOf("/");
1118+
var pathPrefix = path.substring(0, lastPartOfPath);
1119+
var pathSuffix = path.substring(lastPartOfPath + 1);
1120+
var updateObject = '{"' + pathSuffix + '" : "' + val + '"}';
1121+
firebase.instance.child(pathPrefix).updateChildren(firebase.toHashMap(JSON.parse(updateObject)));
1122+
}
11151123
resolve();
11161124
} catch (ex) {
11171125
console.log("Error in firebase.update: " + ex);

firebase.ios.js

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1230,7 +1230,16 @@ firebase.setValue = function (path, val) {
12301230
firebase.update = function (path, val) {
12311231
return new Promise(function (resolve, reject) {
12321232
try {
1233+
if (typeof val == "object") {
12331234
firebase.instance.childByAppendingPath(path).updateChildValues(val);
1235+
} else {
1236+
var lastPartOfPath = path.lastIndexOf("/");
1237+
var pathPrefix = path.substring(0, lastPartOfPath);
1238+
var pathSuffix = path.substring(lastPartOfPath + 1);
1239+
var updateObject = '{"' + pathSuffix + '" : "' + val + '"}';
1240+
firebase.instance.childByAppendingPath(pathPrefix).updateChildValues(JSON.parse(updateObject));
1241+
}
1242+
12341243
resolve();
12351244
} catch (ex) {
12361245
console.log("Error in firebase.update: " + ex);

0 commit comments

Comments
 (0)