2013-06-24 47 views
0
查看

有人可以幫助我得到這個骨幹視圖渲染工作?控制檯告訴我「未捕獲的ReferenceError:應用程序沒有定義」,我運行的JavaScript低於:模型及在Backbonejs

(function() { 
    var App = { 
     Router: {}, 
     Model: {}, 
     View: {} 
    }; 

    /** 
    ** Set states adding and removing classes (show and hide view) 
    ** @Helper Template 
    **/ 
    function template(id) { 
     return $('#' + id).html(); 
    } 

    /** 
    ** Set states adding and removing classes (show and hide view) 
    ** @Router Main 
    **/ 
    App.Router.Main = Backbone.Router.extend({ 
     routes: { 
      '':'vignetteNavView', 
      'discover': 'discoverView', 
      'artists': 'artistsView', 
      'milestones': 'milestonesView', 
      'archive': 'archiveView', 
      'about': 'aboutView' 
     }, 

     hidePages: function() { 
      var contentAll = $('.page'); 
       contentAll.removeClass('active'); 
     }, 

     vignetteNavView: function(){ 
      var contentVignetteNav = document.getElementById('vignetteNavWrapper'); 
       this.hidePages(); 
       contentVignetteNav.classList.add('active'); 
     }, 

     discoverView: function() { 
      var contentDiscover = document.getElementById('discoverWrapper'); 
       this.hidePages(); 
       contentDiscover.classList.add('active'); 
     }, 

     artistsView: function() { 
      var contentArtists = document.getElementById('artistsWrapper'); 
       this.hidePages(); 
       contentArtists.classList.add('active'); 
     }, 

     milestonesView: function() { 
      var contentMilestones = document.getElementById('milestonesWrapper'); 
       this.hidePages(); 
       contentMilestones.classList.add('active'); 
     }, 

     archiveView: function(){ 
      var contentArchive = document.getElementById('archiveWrapper'); 
      this.hidePages(); 
      contentArchive.classList.add('active'); 
     }, 

     aboutView: function(){ 
      var contentAbout = document.getElementById('aboutWrapper'); 
      this.hidePages(); 
      contentAbout.classList.add('active'); 

     } 

    }); 

    var mainRouter = new App.Router.Main(); 
    Backbone.history.start(); 


    /** 
    ** Define the Data Model for An Artist 
    **/ 

    //Artist 

    App.Model.Artist = Backbone.Model.extend({ 
     defaults: { 
      "firstName":"Jim", 
      "lastName":"Nutt", 
      "bio":"Born in Pittsfield, Massachusetts in 1938, Jim Nutt spent his childhood moving around the United States with his family, including a brief stop in the Chicago suburbs during high school. In 1957, after finishing high school, Nutt spent a year and a half studying architecture at the University of Pennsylvania before transferring to the School of the Art Institute of Chicago in 1960 to study painting. Soon after his arrival at SAIC he met fellow student Gladys Nilsson, and the two married one year later, in 1961. Nutt received his BFA in 1965.", 
      "work":"A, B, C, etc...", 
      id:1 
     } 
    }); 



    App.View.ArtistView = Backbone.View.extend({ 
     render: function(){ 
      console.log(this.model.get('firstName')); 
     } 
    }); 

    app.view.artistsView = new App.View.ArtistsView({model:App.Model.Artist}); 

    app.view.artistsView.render(); 


})(); 

我知道它並不一定理想,試圖學習JavaScript,同時學習骨幹/的MVC框架,但我仍在嘗試..所以請原諒,如果這是一個相當明顯的問題......並......謝謝!

現在,我想下面的代碼,並接受了同樣的錯誤:

(function() { 
    /** 
    ** @Namespacing 
    **/ 
    var App = { 
     Router: {}, 
     Model: {}, 
     View: {} 
    }; 

    /** 
    ** Set states adding and removing classes (show and hide view) 
    ** @Helper Template 
    **/ 
    function template(id) { 
     return $('#' + id).html(); 
    } 

    /** 
    ** Set states adding and removing classes (show and hide view) 
    ** @Router Main 
    **/ 
    App.Router.Main = Backbone.Router.extend({ 
     routes: { 
      '':'vignetteNavView', 
      'discover': 'discoverView', 
      'artists': 'artistsView', 
      'milestones': 'milestonesView', 
      'archive': 'archiveView', 
      'about': 'aboutView' 
     }, 

     hidePages: function() { 
      var contentAll = $('.page'); 
       contentAll.removeClass('active'); 
     }, 

     vignetteNavView: function(){ 
      var contentVignetteNav = document.getElementById('vignetteNavWrapper'); 
       this.hidePages(); 
       contentVignetteNav.classList.add('active'); 
     }, 

     discoverView: function() { 
      var contentDiscover = document.getElementById('discoverWrapper'); 
       this.hidePages(); 
       contentDiscover.classList.add('active'); 
     }, 

     artistsView: function() { 
      var contentArtists = document.getElementById('artistsWrapper'); 
       this.hidePages(); 
       contentArtists.classList.add('active'); 
     }, 

     milestonesView: function() { 
      var contentMilestones = document.getElementById('milestonesWrapper'); 
       this.hidePages(); 
       contentMilestones.classList.add('active'); 
     }, 

     archiveView: function(){ 
      var contentArchive = document.getElementById('archiveWrapper'); 
      this.hidePages(); 
      contentArchive.classList.add('active'); 
     }, 

     aboutView: function(){ 
      var contentAbout = document.getElementById('aboutWrapper'); 
      this.hidePages(); 
      contentAbout.classList.add('active'); 

     } 

    }); 

    var mainRouter = new App.Router.Main(); 
    Backbone.history.start(); 


    /** 
    ** Define the Data Model for An Artist 
    **/ 

    //Artist 

    App.Model.Artist = Backbone.Model.extend({ 
     defaults: { 
      "firstName":"Jim", 
      "lastName":"Nutt", 
      "bio":"Born in Pittsfield, Massachusetts in 1938, Jim Nutt spent his childhood moving around the United States with his family, including a brief stop in the Chicago suburbs during high school. In 1957, after finishing high school, Nutt spent a year and a half studying architecture at the University of Pennsylvania before transferring to the School of the Art Institute of Chicago in 1960 to study painting. Soon after his arrival at SAIC he met fellow student Gladys Nilsson, and the two married one year later, in 1961. Nutt received his BFA in 1965.", 
      "work":"A, B, C, etc...", 
      id:1 
     } 
    }); 

    var artist = new App.Model.Artist({}); 



    App.View.ArtistView = Backbone.View.extend({ 
     render: function(){ 
      console.log(this.model.get('firstName')); 
     } 
    }); 

    artistsView = new App.View.ArtistsView({model:artist}); 

    artistsView.render(); 


})(); 
+0

在頂部聲明的'App'的定義是大寫,底部的用法是'app' - 不是大寫。 – asawyer

+0

我的資本意見很好,但我得到了同樣的錯誤。 – user2517788

回答

0

對有能力保存到你必須創建它的對象。在App的定義下面加上這個。

var app = { 
    router: {}, 
    model: {}, 
    view: {} 
};