2013-02-12 73 views
1

我有一个编辑视图,用于在每次单击该元素时创建的主干模型。我遇到的问题是编辑视图需要两个Backbone集合来创建编辑表单(它包含两个<select>列表)。Backbone.js - 使用子模型构建视图

的观点:

MyApp.elementView = Backbone.View.extend({ 
    events: { 
      'click .edit': 'editForm', 
    }, 
    editForm: function(ev) { 

      var editView = new TimeTrack.Views.EditJob({ 
       model: this.model 
       // This view needs two more collections 
       // for the <select> elements 
      }); 
      ... 
    } 
}); 

实例化视图:

var elementView = new MyApp.elementView({ 
     collection: elementCollection 
}); 

什么是推动所需的集合来编辑视图的最佳方式?我是否需要从elementView的窗体实例化中传递编辑视图的集合?或者有更好的方法来做到这一点?

回答

3

我这样做了,通过查看2集合,1 - 主要和其他如下: to elementView - 第二集合,并在elementView recive她。

例如:路由器 我

initialize: -> 
    (YourNameSpace).secondCollection = new (YourNameSpace).secondCollection 

elements: => 
    view = new (YourNameSpace).elementView(secondCollection: @secondCollection) 
    $('.l-yield').html(view.render().el)