backbone.js - why does backbone think I'm treating an object like a function? -


adding backbone rails app, created post model inside app namespace this

var app = {   this.models.post = new app.models.post(); 

in router, created following route

 "posts/:id": "postdetails" 

when navigate /posts/4, i'm getting uncaught typeerror: object not function error when try call fetch on model this

 postdetails: function (id) {         console.log(id);         var post = new app.models.post({id: id});         this.post.fetch({             success: function (data) {                  $('#content').html(new postview({model: data}).render().el);             }         });     } 

according backbone docs http://backbonejs.org/#model-fetch, should able call fetch on model retrieve data server. why backbone think i'm treating object function?

you're doing this:

this.models.post = new app.models.post(); 

to, presumably, set app.models.post instance of app.models.post model. try this:

var post = new app.models.post({id: id}); 

but can use new operator on function:

new constructor[([arguments])]

parameters

constructor
function specifies type of object instance.

you want say:

var post = new app.models.post({ id: id }); 

or similar.


Comments

Popular posts from this blog

css - Which browser returns the correct result for getBoundingClientRect of an SVG element? -

gcc - Calling fftR4() in c from assembly -

Function that returns a formatted array in VBA -