在遵循< Href>之前如何执行Knockout.js动作 [英] How to perform a Knockout.js action before following an <Href>?

查看:210
本文介绍了在遵循< Href>之前如何执行Knockout.js动作的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在使用knockout.js和Html5时遇到这个问题,但是我还没有找到如何处理它。在这里,最重要的是执行一个点击绑定权限,然后再跟随一个Href到另一个页面。绑定本身有一个ajax方法将数据插入到我的数据库中,所以在遵循所指定的href之前必须执行此绑定。

I came across this issue while working with knockout.js and Html5, I haven't found how to handle it, though. In here, what matter the most is performing a click-binding right before following an Href to another page. The binding itself has an ajax method to insert data into my DB so before following the stated href it's mandatory to perform this binding.

HTML如下所示:

       <div data-role="header" data-theme="b">  
            <a href="secondForm.html" data-icon="back" rel="external"> Back </a>
            <h1> Some Text </h1>  

            <div  class="ui-btn-right"  data-role="controlgroup" 
                   data-type="horizontal">

                 <a data-bind="click: linkCustomer" rel="external"  id="continue" 
                  data-role="button" data-theme="b" href="home.html">Continue</a>

            </div>
        </div>

认为这两个动作都会执行,但是这种信念是错误的。执行的唯一操作是Href。

It's thought that both actions would be performed, but that belief is wrong. The only action which is performed is the Href.

我的代码中是否有任何错误?

Do I have any error within my code?

推荐答案

您尝试执行一些js脚本,但同时您的浏览器正在重定向到href。

You try to execute some js scripts, but in the same time, your browser is redirecting to the href.

要解决这个问题,如果你使用角度,可以使用承诺;否则,您必须停止事件传播,处理您的内容,然后在完成后重定向到link.href属性。

To fix this, if you are using angular, you can use promises; otherwise, you have to stop the event propagation, process to you stuff, and then, redirect to the link.href attribute when done.

这篇关于在遵循&lt; Href&gt;之前如何执行Knockout.js动作的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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