1

我正在通过backbone.js 破解/学习我的方式。出于某种原因,我可以一直跟踪 @account 模型实例到视图,但是在模板中,当我什么都不做时<%= account.get('name') %>会返回。当我这样做时,<%= account %>我得到[object Object]

我只是使用错误的标签来显示account吗?

无论如何,这是我的代码。

路由器:shows.js.coffee:

class AppName.Routers.Shows extends Backbone.Router
  routes:
    '': 'index'

  initialize: ->
    # Fetch Show Dates
    @collection = new AppName.Collections.Shows
    @collection.fetch()
    # Fetch Account Info
    @account = new AppName.Models.Account
    @account.fetch()

  index: ->
    # Shows
    view = new AppName.Views.ShowsIndex(collection: @collection)
    $('div.shows_container').html(view.render().el)
    # Account
    view = new AppName.Views.Account(model: @account)
    $('div.account_container').html(view.render().el)

型号:show.js.coffee

class AppName.Models.Account extends Backbone.Model
  urlRoot: 'api/account'

查看:show.js.cofee

class AppName.Views.Account extends Backbone.View
  template: JST['accounts/show']

  render: ->    
    $(@el).html(@template(account: @model)) 
    this

模板:show.jst.ejs

<%= account.get('name') %>
4

0 回答 0