假设我尝试在最终的 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 的框架将它放在路由器中:
咖啡BB路由器
show: (id) ->
visual = @visuals.get(id)
@view = new AiProject.Views.Visuals.ShowView(model: visual)
$("#visuals").html(@view.render().el)
所以,如果是这样的话,也许我应该尝试在@words
那里疯狂?