Backbone.js / Marionette - 更新区域触发无限循环,页面刷新

时间:2014-01-26 22:12:21

标签: javascript backbone.js marionette

我不完全确定这里发生了什么。我有一个模块,负责在我页面的某个区域显示导航。无论出于何种原因,当我触发显示(Manager.trigger("navigation:show");)时,整个页面都会刷新,并继续无限制地刷新。

我一直在盯着这一段时间试图准确追踪到底发生了什么事,但最好还是踩了一会儿。我假设在某处发生了一些递归,但到目前为止我还没有能够跟踪它。

navigation_app.js

Manager.module("NavigationApp", function(NavigationApp, Manager, Backbone, Marionette, $, _) {
    NavigationApp.Router = Marionette.AppRouter.extend({
        appRoutes: {
        }
    });

    var API = {
        showNavigation: function() {
            NavigationApp.Show.Controller.showNavigation();
        },
    };

    Manager.on("navigation:show", function() {
        API.showNavigation();
    });

    Manager.addInitializer(function() {
        new NavigationApp.Router({
            controller: API
        });
    });
});

navigation_controller.js

Manager.module("NavigationApp.Show", function(Show, Manager, Backbone, Marionette, $, _) {
    Show.Controller = {
        showNavigation: function() {    
            console.log("showNavigation() called");
            var navigation = Manager.request("navigation:entities");

            var navigationView = new Manager.NavigationApp.Show.NavigationView({
                collection: navigation
            }); 

            Manager.navigationRegion.show(navigationView);
        }
    }
});

navigation_view.js

Manager.module("NavigationApp.Show", function(Show, Manager, Backbone, Marionette, $, _) {
    Show.NavigationItemView = Marionette.ItemView.extend({
        template: "#navigation-item-view",

        events: {
        },
    });

    Show.NavigationView = Backbone.Marionette.CompositeView.extend({
        template: "#navigation-view",
        itemView: Show.NavigationItemView,
    });
});

Callstack (这只是重复,页面重新加载,并再次重复)

x.Callbacks.c
x.Callbacks.p.fireWith
k
x.ajaxTransport.send.r
x.ajaxTransport.send
x.extend.ajax
x.extend._evalUrl
x.fn.extend.domManip
x.fn.extend.append
c.extend.open
c.extend.show
Show.Controller.showNavigation

0 个答案:

没有答案