2013-04-02 8 views
1

'backbone-on-rails'# https://github.com/meleyal/backbone-on-rails 보석을 사용하고 있는데 공백 양식으로 '새 견적'보기를 만들려고합니다. 매우 간단해야합니다. : S하지만이 오류가 발생합니다 :백본 : 잡히지 않은 ReferenceError : 속성이 정의되지 않았습니다.

설명되지 않음 ReferenceError : 설명이 정의되지 않았습니다. 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> 

도움이 정말 감사합니다. :)

+0

이 간단한 JSON 객체와 백본 외부에서 템플릿을 테스트 할 수하려고? 이 오류가 나타나는 다른 이유를 볼 수 없습니다. – Loamhoof

+0

'model.toJSON()'을 템플릿에 전달하고 있지만 템플릿에서'description' 변수를 찾고 있습니다. 템플릿에서 원하는 것은 실제로'model.description' 일 가능성이 높습니다. 그것을 시도하고 그것이 작동하는지보십시오. 그것이 문제가 아니라면 설명이 모델에 존재하는지 확인하십시오. – DigTheDoug

+1

@DigTheDoug : @ model.toJSON()은 무엇인가 (백본 온 레일과 같은) 기본 'toJSON' 동작을 변경하지 않는 한'{description : null}'을 반환해야합니다. 레일스는'{quote : {description : ...}} '를보고 싶을 것이므로 백본 - 온 레일 (backbone-on-rails)이하는 일을 살펴볼 것입니다. 그래서'console.log (@ model.toJSON())'이'render' 안에서 무슨 말을해야하는지 궁금합니다. –

답변

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())) 
관련 문제