Warning: file_get_contents(/data/phpspider/zhask/data//catemap/8/meteor/3.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Backbone.js 主干:未捕获引用错误:未定义属性_Backbone.js - Fatal编程技术网

Backbone.js 主干:未捕获引用错误:未定义属性

Backbone.js 主干:未捕获引用错误:未定义属性,backbone.js,Backbone.js,我正在使用gem'backboneonrails'#并试图创建一个带有空白表单的“newquote”视图。应该很简单但是我得到的只是这个错误: 未捕获引用错误:未通过调试定义描述错误似乎发生在View->render方法上 代码如下: 路由器: class SpencerGrafica.Routers.Quotes extends Backbone.Router routes: 'new' : 'newQuote' newQuote: ->

我正在使用gem'backboneonrails'#并试图创建一个带有空白表单的“newquote”视图。应该很简单但是我得到的只是这个错误:

未捕获引用错误:未通过调试定义描述错误似乎发生在View->render方法上

代码如下:

路由器:

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

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

模型

模板

<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>

非常感谢您的帮助。:)

试试看

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

  initialize: ->
    @render()

  render: =>  # fat arrow here
    $(@el).html(@template(@model.toJSON()))

你能用一个简单的JSON对象在主干网外测试你的模板吗?我看不出出现此错误的任何其他原因。您正在将
model.toJSON()
传递到模板,但在模板中查找名为
description
的变量。很可能您想要的模板实际上是
model.description
。试试看它是否有效。如果这不是问题所在,请确保模型上存在描述。@DigTheDoug:the
@model.toJSON()
应该返回
{description:null}
,除非某些东西(例如rails上的主干)更改了默认的
到JSON
行为;Rails希望看到
{quote:{description:…}}
,所以我想看看Rails上的主干正在做什么。所以我想知道
console.log(@model.toJSON())
render
里面有什么要说的。通过添加
console.log(@model.toJSON())
像这样:
render:->console.log(@model.toJSON())$(@el.html(@template(quote:@model))
我得到这个:
Object{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>
class SpencerGrafica.Views.NewQuote extends Backbone.View
  el: '#app'
  template: JST["quotes/new"]

  initialize: ->
    @render()

  render: =>  # fat arrow here
    $(@el).html(@template(@model.toJSON()))