输入栏显示NaN [英] input field displaying NaN

查看:127
本文介绍了输入栏显示NaN的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

说明

您好,我正在使用淘汰赛.我有三个复选框和一个输入字段.当我单击复选框时,复选框的值应出现在输入字段中.但是,我没有看到复选框的值,而是看到了NaN.

Hi, I am using knock out. I have three checkboxes and an input field. When I click on checkbox, the value of the checkbox should appear on the input field. However, instead of getting the value of the checkbox, I see NaN.

jsFiddle链接

jsFiddle link

function ViewModel() {
    var self = this;  
    self.primaryClass = ko.observable("50"); 
    self.secondaryClass = ko.observable("40"); 
    self.otherClass = ko.observable("10"); 

    self.selectedValues = ko.observableArray([]);

    self.sum = ko.computed(function () {
        var total = 0;
        ko.utils.arrayForEach(self.selectedValues(), function (item) {
            total += parseInt(item);
        });
        return total;
    });

}

ko.applyBindings(new ViewModel());

推荐答案

检查一下:

http://jsfiddle.net/Dtwigs/uFQdq/5/

执行这样的输入以使其动态:

Do your inputs like this to make them dynamic:

<label>
<input data-bind="checked: selectedValues, value: primaryClass" type="checkbox"></input>
<span data-bind="text: primaryClass"></span>
</label>

将您的值更改为文本值.

Change your values to the values in text.

这篇关于输入栏显示NaN的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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