jquery - Backbone fetch() always returns same model -


for reason, code returning same model though can see correct id being passed in after select item in listview page.

// main.js (relavent function)      venuedetails: function (id) {         // here, id correct         var venue = new venue({_id: id});         venue.fetch({success: function(){             // here, id of venue changed reason             console.log(venue.id);             $("#content").html(new venueview({model: venue}).el);         }});         this.headerview.selectmenuitem();     }, 

the model,

// model.js (relavent model)      var base = 'http://localhost:3000';      window.venue = backbone.model.extend({         urlroot: base+"/venues",         idattribute: "_id",     });      window.venuecollection = backbone.collection.extend({         model: venue,         url: base+"/venues?populate=true"     }); 

in picture, can see model.id different whats in url enter image description here

edit: added router mapping

var approuter = backbone.router.extend({

routes: {     ""                     : "home",     <!-- venues -->     "venues"               : "venuelist",     "venues/page/:page"    : "venuelist",     "venues/add"           : "addvenue",     "venues/:id"           : "venuedetails", 

i don't know if _id attribute being accessed correctly in model, since venue.fetch seems making call out type of default.

maybe try:

   window.venue = backbone.model.extend({         urlroot: base+"/venues",         idattribute: this.options._id,     }); 

(and pull id options hash)

and if doesn't work, try declaring idattribute dynamically:

   window.venue = backbone.model.extend({         urlroot: base+"/venues",         idattribute: function() { return this.options._id },     }); 

Comments

Popular posts from this blog

plot - Remove Objects from Legend When You Have Also Used Fit, Matlab -

java - Why does my date parsing return a weird date? -

Need help in packaging app using TideSDK on Windows -