渲染集合中的单个项目的视图(不行)
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个小时开始敲打我的脑袋。
由于
答案 0 :(得分:0)
试试这个:
class MyApp.Routers.ProjectsRouter extends Backbone.Router
projects: ->
@projects.fetch().done =>
@view = new MyApp.Views.Projects.IndexView(collection: @projects)
$("#projects").html(@view.render().el)
@view.addAll()
class MyApp.Views.Projects.IndexView extends Backbone.View
render: =>
@$el.html(@template('<div class="row-fluid"></div>'))
this