Backbone牵线木偶布局中的僵尸观点和事件......我有它们吗?

时间:2012-11-23 17:41:28

标签: javascript backbone.js marionette

我想我的Backbone Marionette应用程序中的僵尸视图可能有问题。

  1. 如何检查未关闭的视图和内存泄漏?我正在使用适用于Firefox的illuminations-for-developers.com附加组件,当我在我的应用程序中移动时,我看到在“小部件”照明选项卡中堆积了1000多个视图 - 当我检查HTML时,大多数是不在DOM中。这些僵尸视图?
  2. 如果我以正确的方式攻击问题,请添加我在下面使用的代码,以获取人们的意见。
  3. 我正在尝试构建类似于Facebook多朋友选择器对话框的UI(参见图片)。

    我有一个包含两个集合视图的布局,一个填充了用户列表,另一个是添加了所选用户的空集。

    我想在我的应用的多个区域使用此布局。所以我构建了一个控制器对象来处理初始化它并加载集合的数据,然后我初始化它并在需要时在另一个区域显示它。

    非常感谢如何解决这个问题,谢谢。

    Codez:

    MyApp.UserFilterController

    MyApp.UserFilterController = (function(){
    var UserFilterController = {};
    var selectedUsersCol;
    var userFilterColView;
    var selectedUsersColView;
    var usersCol;
    
    UserFilterController.initialize = function ( callback, excludeUsers ) {
        // make a query...
        // exclude the users...
        var usersQ = new Parse.Query(Parse.User);
        // just users with email addresses
        usersQ.exists('email');
        usersQ.exists('name');
        usersQ.limit(1000);
        usersQ.ascending('name');
        usersQ.notContainedIn('objectId',excludeUsers);
        usersCol = usersQ.collection();
        // tell it where to render... append to the body give it an element?
    
        userFilterColView = new MyApp.UserFilterUserCollectionView({
            collection:usersCol
        });
    
        usersCol.fetch({
            success:function (col) {
                console.log("users collection fetched", col.length);
            },
            error:function () {
                console.log("error fetching users collection");
            }
        });
    
        $('#subpage-header').text("Users Selection");
    
        // empty collection to hold the selected users
        selectedUsersCol = new MyApp.Users();
        // view to show the selected users
        selectedUsersColView = new MyApp.SelectedUserCollectionView({
            collection:selectedUsersCol
        });
        _.extend(selectedUsersCol, newBackboneAddMethod());
    
        MyApp.userFilterLayout = new MyApp.UserFilterLayout();
    
        MyApp.slideUp.content.show(MyApp.userFilterLayout);
    
        MyApp.userFilterLayout.selectedusers.show(selectedUsersColView);
        MyApp.userFilterLayout.allusers.show(userFilterColView);
    
        //When user clicks on user in all users then its added to selected users
        userFilterColView.on("itemview:clicked", function(childView, model){
            console.log(model);
            selectedUsersCol.add(model);
        });
    
    
        userFilterColView.on("collection:rendered", function(childView, model){
            console.log('its rendered');
        });
    
        //When user clicks on selected user then it is removed from the collection
        selectedUsersColView.on("itemview:clicked", function(childView, model){
            console.log(model);
            console.log(model.id);
            selectedUsersCol.remove(model);
        });
    
        MyApp.App.vent.bind("slideUp:send",function(){
            console.log("send button has been clicked. attempting call back")
            callback(selectedUsersCol);
        });
    
        //unbinds the trigger above when view is being closed
        userFilterColView.on('collection:before:close', function (){
            MyApp.App.vent.unbind("slideUp:send");
            console.log('colView before:close')
        });
    };
    
    UserFilterController.removeUser = function ( user ) {
        //console.log("you asked to remove", usersArray.length, 'users');
        selectedUsersCol.remove(user);
        usersCol.remove(user);
    };
    UserFilterController.generateListview = function ( user ) {
        userFilterColView.$el.listview();
    };
    UserFilterController.resetSelected = function (user) {
        selectedUsersCol.reset();
    };
    UserFilterController.cleanup = function () {
        console.log("its closing");
        //selectedUsersColView.unbindAll();
        //        selectedUsersColView.close();
        userFilterColView.close();
       // userFilterLayout.unbindAll();
        //        MyApp.userFilterLayout.close();
        //        MyApp.slideUp.content.close();
       // MyApp.slideUp.close();
    };
    
    return UserFilterController;
    }());
    

    MyApp.EventDisplayLayout

    MyApp.EventDisplayLayout = Backbone.Marionette.Layout.extend({
        template: '#event-display-layout',
        id: "EventDisplayLayout",
    
        events: {
            'click #invite':  'showUserFilter'        
        },
    
        // User clicked on 'invite' button
        showUserFilter: function () {        
            $.mobile.changePage($('#subpage'), {changeHash: false,transition: 'slideup'});
            MyApp.UserFilterController.generateListview();
        }
    }
    

    MyApp.showEventDisplay

    MyApp.showEventDisplay = function (event) {
    var eventDisplayLayout = new MyApp.EventDisplayLayout({});
    MyApp.App.mainRegion.show(eventDisplayLayout);    
    
    var Invitees = event.get("invitees");
    var excludeIds = [];
    _.each(Invitees,function(invitee){
        excludeIds.push(invitee.id);
    });
    MyApp.UserFilterController.initialize(function (selectUsersCol){
        console.log("In call back: ",selectUsersCol);
    },excludeIds);
    };
    

    MyApp.SlideUpPageLayout

    // The generic layout used for modal panel sliding up from bottom of page.
    MyApp.SlideUpPageLayout = Backbone.Marionette.Layout.extend({
        el: '#subpage',
        //template: '#homepage-temp',
        regions: {
            header: '.header',
            content: '.content'
        },
        events:{
            'click .send':'slideUpSend',
            'click .cancel':'slideUpCancel'
        },
        onShow: function () {
            console.log("SlideUpPage onShow");
            this.$el.trigger('create');
        },
        initialize: function () {
            // make user collection...
    
        },
        slideUpSend: function () {
            console.log("send button has been pressed");
            MyApp.App.vent.trigger('slideUp:send');
            $.mobile.changePage($('.type-home'),{transition: 'slideup',reverse:true});
        },
        slideUpCancel: function () {
       //     MyApp.App.vent.trigger('slideUp:cancel');
            $.mobile.changePage($('.type-home'),{transition: 'slideup',reverse:true});
        }
    });
    

    MyApp.UserFilterLayout

    // The layout used for the user filter panel sliding up from bottom of page.
    MyApp.UserFilterLayout = Backbone.Marionette.Layout.extend({
        template: '#userfilterlayout',
        //template: '#homepage-temp',
        regions: {
            selectedusers: '.selectedusers',
            allusers: '.allusers'
        },
    
        onShow: function () {
            console.log("userfilterlayout onShow");
            this.$el.trigger('create');
        }
    });
    

    Facebook multi-friend selector UI

0 个答案:

没有答案