在knockoutjs中组合href,click和data-bind

时间:2015-08-06 13:14:17

标签: javascript jquery knockout.js

我正在尝试在等待慢速链接时显示某种加载器:

<a href="/api/action/that/takes/some/time" data-bind="click: showLoading">
this.showLoading = function () {
    // Display loader while waiting for the redirect
}

click似乎覆盖了实际链接。有办法解决这个问题吗?

澄清编辑: 我可以做这样的事情,但我更喜欢将网址保留在href上,只需将showLoading位添加到需要一些时间的链接

<a href="#" data-bind="click: showLoading.bind($data, '/api/action/that/takes/some/time'">

this.showLoading = function(link) {
    // Display loader while waiting for the redirect
    window.location.href = link;
};

1 个答案:

答案 0 :(得分:4)

您只需要return true处理程序click触发浏览器的默认操作:

this.showLoading = function () {
    // Display loader while waiting for the redirect
    return true;
}

在文档中也可以看到它:Allowing the default click action