javascript - Can't get Firebase update() to work with provided object -
ok, after lot of trial , error have try asking here. i'm trying update firebase entry , code this,
this service.js:
//this dosn't work var updateitem = function (item, id) { var ref = new firebase(firebase_uri + '/lessons/' + id); ref.$update(item); } //this works (items ref new firebase(firebase_uri + '/lessons/'); var additem = function (item) { items.$add(item); }
and controller:
$scope.updatelesson = function (item) { lessonsservice.updatelesson(item, id); }
the error i'm getting this:
error: firebase.set failed: first argument contains invalid key ($id). keys must non-empty strings , can't contain ".", "#", "$", "/", "[", or "]"
the object i'm passing in looks this:
object { $id: "-jliuvvmlqocvghaed9f", $bind: function, $add: function, $save: function, $set: function…} $add: function (item) { $auth: function (token) { $bind: function (scope, name, defaultfn) { $child: function (key) { $getindex: function () { $getref: function () { $id: "-jliuvvmlqocvghaed9f" $off: function (type, callback) { $on: function (type, callback) { $remove: function (key) { $save: function (key) { $set: function (newvalue) { $transaction: function (updatefn, applylocally) { $update: function (newvalue) { createdate: "2014-04-24t11:29:42.692z" desc: "test" somemorevalues: "here" }
i have tried json.stringify on object , got nice looking result looking this:
{ createdate: "2014-04-24t11:29:42.692z", desc: "test", somemorevalues: "here" }
but wont accept when i'm passing in thru variable. (error: firebase.update failed: first argument must object containing children replace.) if pass in directly string works thou (?!!!). it's exact same information in variable.. hell missing?! of i'm building own object this:
var newitem = { title: item.title, desc: item.desc, ingress: item.ingress, workarea: item.workarea, years: {val: item.years.val}, }
and passing along firebase, works not ideal because "static".
use angularfire according the api. read angular+firebase overview primer.
in essence, instead of passing angularfire objects firebase ref (which not work since keys may not have $ in name) , calling update/set yourself, use $set
/$update
methods available on $firebase object:
var ref = $firebase(url); ref[id].desc = 'foo'; ref.$save(id).then(oncomplete);
Comments
Post a Comment