在淘汰赛中未选中复选框 [英] Checkbox doesn't get checked in knockout

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

问题描述

我有一个复选框和用于更新数据的复选框的单击事件.当我单击复选框时,数据正在更新,但未选中该复选框.

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 代码:

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.

推荐答案

参见:http://knockoutjs.com/documentation/click-binding.html

注意 3:允许默认点击操作
默认情况下,淘汰赛将阻止点击事件采取任何默认操作.这意味着如果您在 a 上使用点击绑定标签(一个链接),例如,浏览器只会调用你的处理程序功能,不会导航到链接的 href.这是一个有用的默认是因为当你使用点击绑定时,通常是因为您将链接用作操作视图的 UI 的一部分模型,而不是作为到另一个网页的常规超链接.

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.


编辑:添加了显示函数中返回 true 的位置的示例.它必须从实际函数本身返回,而不是 Ajax successerror 处理程序.


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天全站免登陆