javascript - Backbone.sync scope issues -
i'm using backbone.sync
send collection php function, stores information in database , returns data based on his.
everything works until success function of .sync()
, lose scope of model , collection can't update them, there way around this?
i've tried using 2 methods , neither seem return anything, , can't find more information on subject on here or google. it's in preferences avoid using model.save()
, it's many calls backend.
method 1 ;
var that=this; // logic done here backbone.sync("update",this.collection,{ success:function(data){ // attempt update this.collection here, `that` out of scope // , scope of `this` different } });
method 2 :
var that=this; var ondatahandler=function(data){ // attempt update this.collection here, `that` out of scope // , scope of `this` different }; // logic done here backbone.sync("update",this.collection,{ success:ondatahandler });
does know way around problem? checked backbone documentation , noticed collection.fetch()
function delegates .sync()
, , yet 2nd method 1 use .fetch()
, works fine in keeping scope of that
try:
var that=this; var prebindhandler=function(data){ // attempt update this.collection here, `that` out of scope // , scope of `this` different }; successhandler = prebindhandler.bind(this); // logic done here backbone.sync("update",this.collection,{ success:successhandler });
Comments
Post a Comment