私は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') %>