Backbone.js模板对象无法显示

时间:2012-11-21 19:22:37

标签: backbone.js backbone-views

我正在通过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') %>

0 个答案:

没有答案