【问题标题】:Backbone: Passing variables from router to viewBackbone:将变量从路由器传递到视图
【发布时间】:2012-10-21 17:56:14
【问题描述】:

我有一个骨干路由器有

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

在其initialize 方法中。

在路由器的new方法中,有这样的:

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

@collection 变量传入就好了,但在render() 中,console.log @flashes 返回undefined

那么,我错过了什么?

【问题讨论】:

    标签: javascript backbone.js coffeescript


    【解决方案1】:

    @flashes 变量作为选项传递。所以你必须尝试这样的事情:console.log @this.options.flashes

    【讨论】:

      猜你喜欢
      • 2014-08-23
      • 1970-01-01
      • 2015-06-05
      • 1970-01-01
      • 2021-12-28
      • 1970-01-01
      • 2015-10-07
      • 1970-01-01
      • 2012-02-10
      相关资源
      最近更新 更多