Still struggling to learn Backbone. Currently, my views aren't rendering at all due to some unknown, unreported error that's happening after I call .fetch()
on my Backbone Collection. Since this can come from any place in my application, I've set up a gist for you to view all the files.
Link to all the code.
The comments in the view should explain the errors that are happening and als开发者_运维技巧o the response from the server (which is simply just Sinatra + Redis). The response from /schools
is [{"name":"Foo"},{"name":"Bar"}]
, but I don't see why that would cause an error. My view is never initialized for some reason, even though I create a new window.fooView
in my router. Can anyone help me out? Thanks!
Looks like you never call your view's render
method. You should do this explicitly in router.js line 8 or at the end of index.js initialize
line 12. Some folks like to automatically render the view after initialize
, but by default backbone expects you to do it explicitly whenever you want. I think your schools.bind
will do this for SUBSEQUENT changes, but the way the code runs, you fetch the schools, which fires events, and THEN you make your view and bind it, so by the time your view is bound, no more events fire, and thus render
doesn't get called. A working example would be easier to debug for sure, but that's my guess by reading the gist.
精彩评论