如何刷新页面中的骨干应用 [英] How to refresh a page in a backbone application

查看:111
本文介绍了如何刷新页面中的骨干应用的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我使用的骨干,建立我的web应用程序。

I am using backbone to build my web app.

目前我面临的一个问题,即如果我在主页上,我无法仅通过对家的按钮,点击再度刷新同一个页面。

Currently I am facing an issue whereby if I am on the home page, I am unable to refresh the same page by just clicking on the 'home' button again.

我认为,这是骨干网提供的限制(不加载,如果相同的URL被称为页)

I believe that this is the limitation provided by backbone (does not reload the page if the same URL is called)

有没有解决这个办法吗?所以,我可以触发页面重载当我点击home键一次即再次拨打同一URL?

Is there any way around this? So that I can trigger a page reload when I click on the home button again i.e. call the same URL again?

推荐答案

综观Backbone.js的来源,它好像这是不可能的默认,因为它只响应一个URL的变化。而且,由于点击同一个链接,你就不会触发更改事件。

Looking at the backbone.js source, it seems as though this is not possible by default, since it only responds to a url change. And since clicking the same link, you would not trigger a change event.

code在Backbone.History:

Code in Backbone.History:

$(window).bind('hashchange', this.checkUrl);

您需要处理非改变自己。下面是我所做的:

You'll need to handle a non-change yourself. Here's what I did:

$('.nav-links').click(function(e) {
    var newFragment = Backbone.history.getFragment($(this).attr('href'));
    if (Backbone.history.fragment == newFragment) {
        // need to null out Backbone.history.fragement because 
        // navigate method will ignore when it is the same as newFragment
        Backbone.history.fragment = null;
        Backbone.history.navigate(newFragment, true);
    }
});

这篇关于如何刷新页面中的骨干应用的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆