【问题标题】:How to disable backbone.js from adding /# when dialog is closed如何在对话框关闭时禁用backbone.js添加/#
【发布时间】:2015-06-05 07:10:49
【问题描述】:

当我加载我的主干页面并按下返回按钮时,它会将 /# 添加到 url。如果我再次单击返回,它会从 rails 主页视图加载空索引页面。我可以通过关闭 turbolink 来解决这个问题。

但是,当我打开任何foundation.js 对话框时,它还会将相同的/# 附加到url。现在,当我回击而不是转到上一页时,它会再次加载空的 rails 主页而不是加载主干页面。

如何防止主干添加此 /# 哈希。

我的 rails 索引页面是:

<div class="containing_div"><div>
<%= javascript_tag do -%>
    (function () {
       MyApp.initialize();
    })();
<% end -%>

而我的初始化函数是:

  initialize: function(){
    this.private.biography = new MyApp.Models.BiographyModel();
    this.private.purposeModel = new MyApp.Models.PurposeModel();
    new MyApp.Routers.Welcome();
    if(!Backbone.History.started){
     Backbone.history.start();
    }
    this.initializeData();
  }

我的路由器是:

MyApp.Routers.Welcome = Support.SwappingRouter.extend({

    initialize: function(options){
        this.el = $('div.containing_div');
    },
    routes: {
        "": "index"
    },

    index: function(){
        var view = new MyApp.Views.WelcomeIndex();
        this.swap(view);
    }
})

这就是我关闭模式的方式:

$('#profileModal').foundation('reveal', 'close', {
    animation: 'none'
});

【问题讨论】:

    标签: javascript jquery ruby-on-rails backbone.js zurb-foundation


    【解决方案1】:

    我猜是为了打开/关闭您正在使用的模式,这是切换到 /# 的默认浏览器行为。您应该使用常规(顺便说一句,可以在 之外使用)或在单击时禁用事件传播。

    【讨论】:

    • 谢谢。现在我已经能够通过使用 e.preventDefault() 来解决这个问题。但我想知道是否有更好的方法(更骨干的方法)来实现这一目标。考虑到骨干网如此受欢迎,我无法使用谷歌搜索找到任何解决方案。
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2013-05-03
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2011-02-25
    相关资源
    最近更新 更多