1

我正在使用 gem 'backbone-on-rails' # https://github.com/meleyal/backbone-on-rails并且我正在尝试使用空白表格创建一个“新报价”视图。应该很简单。:S 但我得到的只是这个错误:

Uncaught ReferenceError: description is not defined通过调试,错误似乎发生在 View->render 方法上。

这是代码:

路由器:

class SpencerGrafica.Routers.Quotes extends Backbone.Router
    routes:
        'new'       : 'newQuote'

    newQuote: ->
        new SpencerGrafica.Views.NewQuote model: new SpencerGrafica.Models.Quote

看法:

class SpencerGrafica.Views.NewQuote extends Backbone.View
  el: '#app'
  template: JST["quotes/new"]

  initialize: ->
    @render()

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

模型

class SpencerGrafica.Models.Quote extends Backbone.Model

  defaults:
    description: null

模板

<form id="new-quote" name="quote">

  <div>
    <input type="text" name="description" value="<%= description %>" placeholder="Descripcion interna">
  </div>

  <div class="actions">
    <input type="submit" value="Add Post" />
  </div>

</form>

任何帮助真的很感激。:)

4

1 回答 1

0

尝试

class SpencerGrafica.Views.NewQuote extends Backbone.View
  el: '#app'
  template: JST["quotes/new"]

  initialize: ->
    @render()

  render: =>  # fat arrow here
    $(@el).html(@template(@model.toJSON()))
于 2013-04-03T02:51:16.180 回答