复选框不淘汰赛得到遏制 [英] Checkbox doesn't get checked in knockout

查看:132
本文介绍了复选框不淘汰赛得到遏制的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个复选框,并单击事件复选框更新数据。当我点击复选框中的数据更新,但该复选框没有得到未选中。

I have a checkbox and click event for checkbox for updating data. When I click on the checkbox the data is updating but the checkbox does not get not checked.

这是我的html code:

This is my html code:

<td>
 <input type="checkbox" data-bind="checked: status, disable: status, click: $root.UpdateStatus" />
</td>

这是我的脚本:

self.UpdateStatus = function (tblUsers) {
    $.ajax({
        type: "POST",
        url: 'SinglePageApp.aspx/UpdateStatus',
        data: "{statusVal: 'true',goalId: " + tblUsers.goalId + "}",
        contentType: "application/json; charset=utf-8",
        success: function (result) {
            alert(result.d);
        },
        error: function (XMLHttpRequest, textStatus, errorThrown) {
            alert(textStatus);
            alert(errorThrown);
        }
    });
};

我要被点击时得到检查我的复选框。而点击复选框认沽更新后的数据之后。

I want my checkbox to get checked when it is clicked. And after that put updated data after checkbox clicked.

推荐答案

查看:<一href=\"http://knockoutjs.com/documentation/click-binding.html\">http://knockoutjs.com/documentation/click-binding.html

注意3:允许默认点击动作结果
  默认情况下,淘汰赛将prevent click事件采取任何
  默认操作。这意味着,如果你使用click上绑定
  标签(链接),例如,浏览器将只调用处理
  功能并不会浏览到该链接的href。这是一个有用的
  默认,因为当你使用click绑定,这是因为正常
  您使用的操纵您的视图的链接作为用户界面的一部分
  模式,而不是作为一个普通的超链接到其他网页。

Note 3: Allowing the default click action
By default, Knockout will prevent the click event from taking any default action. This means that if you use the click binding on an a tag (a link), for example, the browser will only call your handler function and will not navigate to the link’s href. This is a useful default because when you use the click binding, it’s normally because you’re using the link as part of a UI that manipulates your view model, not as a regular hyperlink to another web page.

然而,如果你想让默认的点击动作进行,只是
  从你的点击处理函数返回true



修改添加例如表示将在函数返回真正。它必须从实际函数本身的回报,而不是阿贾克斯成功错误处理程序。


added example showing where to return true in the function. It has to be return from the actual function itself, not the Ajax success or error handler.

self.UpdateStatus = function (tblUsers) {
    $.ajax({
        type: "POST",
        url: 'SinglePageApp.aspx/UpdateStatus',
        data: "{statusVal: 'true',goalId: " + tblUsers.goalId + "}",
        contentType: "application/json; charset=utf-8",
        success: function (result) {
            alert(result.d);
        },
        error: function (XMLHttpRequest, textStatus, errorThrown) {
            alert(textStatus);
            alert(errorThrown);
        }
    });
    // Return true to allow default click action.
    return true;
};

这篇关于复选框不淘汰赛得到遏制的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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