【发布时间】:2012-07-01 18:42:33
【问题描述】:
假设我尝试在最终的 BackBone 视图中加载两个不同的对象。
我的 Rails 控制器
def index
@visuals = Visual.all
@words = Word.all
respond_to do |format|
format.html # index.html.erb
format.json { render json: [@visuals, @words] }
end
end
我可以添加的地方就在这里:
我的 Rails 视图:
#visuals
:javascript
$(function() {
window.router = new AiProject.Routers.VisualsRouter({test_visuals: #{ @visuals.to_json.html_safe } });
// AiProject.words = new Words(#{@words.to_json});
// ^^ Would this be the best place to insantiate my controller code's instance variable?
Backbone.history.start();
});
但其他人说要把它放在你的模板中。这很奇怪,因为我认为我的 BackBone 的框架将它放在路由器中:
Coffee BB 路由器
show: (id) ->
visual = @visuals.get(id)
@view = new AiProject.Views.Visuals.ShowView(model: visual)
$("#visuals").html(@view.render().el)
那么如果是这样的话,也许我应该尝试在那里对@words 进行幻化?
【问题讨论】: