0

除了在初始化之外,我在使用路由器 cfunctions 调用我的视图时遇到问题。

这是我的路由器代码:

var ApplicationRouter = Backbone.Router.extend({
        routes: {
                "": "home",
               //"*actions": "home",
                "photo-gallery": "gallery",
                "sound-lounge": "sound",
                "contact": "contact"
        },
        initialize: function() {
               this.homeView = new window.app.HomeView();
               this.homeView.render();

               /*
               var soundView = new window.app.SoundView();
                soundView.render();

                var contactView = new window.app.ContactView();
                contactView.render();

                var galleryCollection = new window.app.GalleryCollection();
        var gallery_items = galleryCollection.fetch();
         gallery_items.done(function(){
           var gallery_item = new GalleryView({ collection: galleryCollection });
         });
         */



        },
        home: function() {

                console.log('home');
        },
        sound: function() {
               //var soundView = new window.app.SoundView();
                //soundView.render();
                console.log('sound');
        },
         contact: function() {
               //var contactView = new window.app.ContactView();
               // contactView.render();
                console.log('contact');
        },
        gallery: function() {

            console.log('gallery');

        }
});

你可以看到我有:

var soundView = new window.app.SoundView();
soundView.render();

在 initalize 函数中注释掉,这将起作用,但只要我把它放在“声音”函数中,我就会收到这个错误:Uncaught TypeError: undefined is not a function

这与这部分有关:new window.app.SoundView();

我在我的代码中将它称为 window.app.SoundView,我该如何让它工作(我的所有部分都发生错误)

// 添加声音查看代码

    // SOUNDVIEW    
window.app.SoundView = Backbone.View.extend({
    el: $("html"),
    events: {
      "click #sound-lounge": "render_sound"
    },
    initialize: function(){
        this.render_sound();
    },
    render: function(model){
        return this;
    },
    render_sound: function(){
        this.model=new window.app.Home({id: 2});
        var $main=this.$el.find('#content-area');
        this.model.fetch().complete(function(data){
            $main.html(data["responseJSON"].description);
        });
    }
});

谢谢

4

1 回答 1

0

我的问题最终就像删除 window.app 一样简单。来自 soundView 变量名。

例如

window.app.SoundView = Backbone.View.extend({ == SoundView = Backbone.View.extend({

var soundView = new window.app.SoundView(); == var soundView = new SoundView();

于 2013-09-18T20:38:50.173 回答