【发布时间】:2014-02-20 17:51:01
【问题描述】:
- 获取集合(正常)
- 索引渲染视图(确定)
-
为集合中的单个项目渲染视图(不正常)
class MyApp.Routers.ProjectsRouter extends Backbone.Router initialize: -> @projects = new MyApp.Collections.ProjectsCollection() routes: "projects" : "projects" projects: -> @projects.fetch().done => @view = new MyApp.Views.Projects.IndexView(collection: @projects) $("#projects").html(@view.render().el) class MyApp.Views.Projects.IndexView extends Backbone.View template: JST["backbone/templates/projects/index"] addAll: => @collection.each(@addOne) addOne: (project) => view = new MyApp.Views.Projects.ProjectView({ model: project }) **$(".row-fluid").append(view.render().el)** render: => @$el.html(@template('<div class="row-fluid"></div>')) @addAll() this class MyApp.Views.Projects.ProjectView extends Backbone.View template: JST["backbone/templates/projects/project"] render: -> @$el.append(@template()) this
".row-fluid" 没有建立,我已经使用 firebug 调试了它。有人请帮助我,我从过去的 5 到 6 小时一直在敲我的头。
谢谢
【问题讨论】:
-
愚蠢的问题,但在模板中找到
.row-fluid?愿意展示模板代码吗? -
你能准备一些简单的jsFiddle吗? $(".row-fluid") 是全局选择器,所以你的 DOM 树中没有这样的元素。
-
缺少大括号传入集合 ->
@view = new MyApp.Views.Projects.IndexView({collection: @projects}) -
@msvalkon 添加模板代码@$el.html(@template(''))
标签: ruby-on-rails backbone.js coffeescript