nockoutjs radiobutton点击事件
我有一些HTML:
<input name="Test" type="radio" value="yes" data-bind="checked: Page2.Traded, click: Traded_Yes" /> Yes
<input name="Test" type="radio" value="no" data-bind="checked: Page2.Traded, click: Traded_No" /> No
还有一些JavaScript:
self.Traded_Yes = function(data) {
$("#Page2Symbol").prop("disabled", false);
return true;
};
self.Traded_Yes = function(data) {
$("#Page2Symbol").prop("disabled", true);
return true;
};
在禁用ID:Page2Symbol和保存正确的数据方面,UI上的一切正常,但是UI在我单击任何一个收音机时都不会显示在Yes/no之间的广播按钮。我做返回true
以允许默认单击操作,如下所示: https://knockoutjs.com/documentation/click-binding.html ,但是当我单击一个收音机时,UI不会翻转选择。有什么想法发生了什么事?
I have some html:
<input name="Test" type="radio" value="yes" data-bind="checked: Page2.Traded, click: Traded_Yes" /> Yes
<input name="Test" type="radio" value="no" data-bind="checked: Page2.Traded, click: Traded_No" /> No
And some Javascript:
self.Traded_Yes = function(data) {
$("#Page2Symbol").prop("disabled", false);
return true;
};
self.Traded_Yes = function(data) {
$("#Page2Symbol").prop("disabled", true);
return true;
};
Everything works fine on the UI in terms of disabling id: Page2Symbol, and saving the correct data however the UI doesn't show the radio button flipping between Yes/No when I click either radio. I doreturn true
in order to allow the default click action as discussed here: https://knockoutjs.com/documentation/click-binding.html , however the UI does not flip the selection when I click either radio. Any ideas what is going on?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
我无法重现您的问题,但是可能有一些很好的建议可以解决您可能遇到的问题:
在使用淘汰赛时,建议与DOM进行 All All 通过敲除绑定。为了禁用和启用按钮,有
禁用
和enable
绑定。以下是您使用它们的方式:使用
disable
绑定:您将
计算
属性添加到视图模型中,以根据交易。 >。
这样可以确保您不需要点击绑定,并且可以摆脱任何
id
引用。该问题的复制失败:
该片段表明您的原始代码应该起作用,即使这有点反图案。
I can't reproduce your issue, but might have some good advice to work around the issue you might have:
When working with knockout, it's advised to make all interaction with the DOM go through a knockout binding. For disabling and enabling a button, there are the
disable
andenable
bindings. Here's how you use them:Using the
disable
binding:You add a
computed
property to your viewmodel that defines whether to disable based on the value ofTraded
.This ensures you don't need that click-binding and can get rid of any
id
references.Failed reproduction of the issue:
This snippet shows that your original code should work, even though it's a bit of an anti-pattern.