我正在使用Twitter Bootstrap按钮组和Knockout.我觉得我忽略了一些非常简单的东西,但是,我无法checked
在这种情况下获得绑定工作.
我有一个jsFiddle在这里重现问题:http: //jsfiddle.net/n5SBa/.
这是小提琴的代码:
HTML
使用Javascript
function SurveyViewModel() { var self = this; self.Score = ko.observable(); //Events self.ClickScore = function (score) { self.Score(score); }; //Computations self.RecommendationLabel = ko.computed(function () { if (self.Score() < 8) { return "Some question?"; } else { return "Some other question?"; } }); self.DOMSelectedScore = ko.computed(function() { if ($('input[name=score]:checked').val()) { return $('input[name=score]:checked').val(); } else { return 'no value!'; } }); }; var surveyViewModel = new SurveyViewModel(); ko.applyBindings(surveyViewModel);
在示例中,我无法在DOM中选择实际的单选按钮,以便可以在我的表单中正确提交.