简体   繁体   English

淘汰赛集视图模型字段值

[英]Knockout set view-model field value

Model has a field, TotalCount . Model有一个字段TotalCount On button click, how I could change its value?单击按钮时,如何更改其值?

    <input id="Qty" type="text" style="width:25px;" 
     value="@Model.TotalCount" />

    var pageKoModel;
    var pageKoModelData = @Html.Raw(Json.Encode(Model));
    $(document).ready(function () {
        pageKoModel = new Object();
        ko.mapping.fromJS(pageKoModelData, {}, pageKoModel);
        ko.applyBindings(pageKoModel);
    });

data-bind is not present in the code.代码中不存在数据绑定。 So, try replacing the input field with this code因此,尝试用此代码替换输入字段

<input id="Qty" type="text" style="width:25px;" data-bind="
value:TotalCount" />

if, still it does not work then,try with如果仍然不起作用,请尝试使用

<input id="Qty" type="text" style="width:25px;" data-bind="
value:pageKoModel.TotalCount" />

this works for me like:这对我有用,例如:

<input tabindex="1" type="text" data-bind="value: $root.TotalCount" maxlength="5" 
onkeypress="return onlyNumberKey(event);" style="width:35px;" />

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM