Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Backbone: Passing variables from router to view

I have a backbone router that has

@collection = new Backbonedemo.Collections.Posts()
@flashes = new Backbone.Collection.Flashes()

in its initialize method.

In the router's new method, there's this:

new: ->
  view = new Backbonedemo.Views.PostsNew(collection: @collection, flashes: @flashes)
  $('#posts_container').html(view.render().el)

The @collection variable passes in just fine, but in render(), console.log @flashes returns undefined.

So, what am I missing?

like image 307
PlankTon Avatar asked Dec 04 '25 17:12

PlankTon


1 Answers

The @flashes variable is passed as an option. So you must try something like this: console.log @this.options.flashes

like image 114
Amulya Khare Avatar answered Dec 06 '25 07:12

Amulya Khare