2013-03-01 4 views
0

Treehouse의 Backbone.js 튜토리얼에 문제가 있습니다. 여기에 내 코드입니다 :정의되지 않은 'new_form'속성을 설정할 수 없습니다.

var NotesApp = (function() { 
    var App = { 
     stores: {} 
    } 

    App.stores.notes = new Store('notes'); 
    // Note Model 
    var Note = Backbone.Model.extend({ 
     //Local Storage 
     localStorage: App.stores.notes, 

     initialize: function() { 
      if (!this.get('title')) { 
       this.set({ 
        title: "Note at " + Date() 
       }) 
      }; 

      if (!this.get('body')) { 
       this.set({ 
        body: "No Body" 
       }) 
      }; 
     } 

    }) 

    //Views 
    var NewFormView = Backbone.View.extend({ 
     events: { 
      "submit form": "createNote" 
     }, 

     createNote: function (e) { 
      var attrs = this.getAttributes(), 
       note = new Note(); 

      note.set(attrs); 
      note.save(); 
     }, 

     getAttributes: function() { 
      return { 
       title: this.$('form [name=title]').val(), 
       body: this.$('form [name=body]').val() 
      } 
     } 

    }); 

    window.Note = Note; 

    $(document).ready(function() { 

     App.views.new_form = new NewFormView({ 
      el: $('#new') 
     }); 

    }) 

    return App 
})(); 

그리고 나는 오류를 얻을 : Cannot set property 'new_form' of undefined

내가 다시 가서 최대한 가까이 코드를 복사하려했지만, 나는 아직도 그 일을 가져올 수 없습니다. 어떤 제안?

답변

3

stores: {} 다음에 , views: {}을 더합니다.

당신은 당신의보기를 부착 할 객체를 필요 - 자바 스크립트는 빠른 응답을위한

+0

감사합니다, 당신의 제안이 도움이 더 vivification이 없습니다. 하지만 지금은 또 다른 오류가 발생합니다 : Uncaught SyntaxError : 예기치 않은 토큰} http://pastebin.com/SKi3UsKB – Mike

+0

'views {}'이 아닌'views : {}'입니다. – Ven

+0

죄송합니다! 고마워, 콘솔에 오류가 없습니다! – Mike

관련 문제