Sunday, September 8, 2013

Unable to execute initialize method of backbone.js view

Unable to execute initialize method of backbone.js view

I am trying to follow episode Railscasts pro related to Backbone.js below
are the code snippets of my router and view. I am not able get the
statememnts inside initialize method of my view.
I didn't find any indentation errors in both of these coffeescript codes.
Same methods are executing
I am very new to coffee script and backbone.js. Sorry, if my problem is
very trivial.
Router
class RafflerBackboneRailsCastsPro.Routers.Entries extends Backbone.Router
routes:
'':'index'
'entries/:id': 'show'
initialize: ->
alert "control is not reaching this statement"
@collection = new RafflerBackboneRailsCastsPro.Collections.Entries()
@collection.fetch({reset:true})
index: ->
view = new
RafflerBackboneRailsCastsPro.Views.EntriesIndex(collection:
@collection)
view.initialize()
$('#container').html(view.render().el)
show:(id)->
alert "Entry #{id}"
My view:
class RafflerBackboneRailsCastsPro.Views.EntriesIndex extends Backbone.View
template: JST['entries/index']
intialize: ->
alert "view initializing"
console.log "from initializing view"
@collection.on('reset',@render, this)
render: ->
alert "in render function of view"
$(@el).html(@template(entries: @collection))
this

No comments:

Post a Comment