由版本2.2.0中的异常键触发的kickout.js值绑定 [英] knockout.js value binding triggered by unusual keys in version 2.2.0

查看:62
本文介绍了由版本2.2.0中的异常键触发的kickout.js值绑定的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

请考虑以下简单示例:

<input data-bind="value: query, valueUpdate: 'afterkeydown'"/>

在基因敲除js 2.1.0中,当我按 ctrl 上箭头下箭头 Shift 绑定已 被触发,并且query未更新.

In knockoutjs 2.1.0, when I press any of ctrl,Up arrow,Down arrow,Shift the binding is not fired and query is not updated.

在基因敲除js 2.2.0中,上述所有按键均会触发绑定.

In knockoutjs 2.2.0, the binding fires for all the above keypresses.

这正在破坏一些现有代码(这是一种自动完成功能,上下箭头通常用于从下拉菜单中进行选择).

This is playing havoc with some existing code (it's an autocomplete, and arrow up and down are frequently used to select from the drop down).

哪种行为是正确的?从技术上讲,我认为后者是正确的,因为按下这些键是一个按下事件,但是绑定不应该仅在值发生更改时才会触发?

Which behaviour is correct? I assume technically, the latter is correct as these pressing these keys is a keydown event, but shouldn't the binding only fire if the value has changed?

我想使所有内容保持实时,并且文档状态:

I want to keep everything real-time, and the docs state:

如果您想实时更新视图模型,

"afterkeydown"是最好的选择

"afterkeydown" is the best choice if you want to keep your view model updated in real-time

建议?

  • ko 2.1.0 demo: http://jsfiddle.net/Rmcza/7/
  • ko 2.2.0 demo: http://jsfiddle.net/Rmcza/8/

推荐答案

我认为这是此更改" .它使计算得到的可观察对象在被触发时始终会写入,即使该值未更改也是如此.

I think this is a result of this change made by RP Niemeyer in Sept. It causes computed observables to always write when triggered, even if the value hasn't changed.

您会在此小提琴中注意到,在以下情况下不会出现 使用非计算的可观察值.我使用显式订阅对其进行了测试,并且该事件不会针对向下箭头触发.

You will notice in this fiddle that this does not occur when using a non-computed observable. I tested this using an explicit subscription, and the event does not fire for the down arrow.

this.test = ko.observable('');
this.test.subscribe(function(newValue) {
    alert("The test value new name is " + newValue);
});

也许Ryan可以解释为什么更改了这种情况,以及在这种情况下为什么计算值的行为与常规可观测值不同.您可能要在GitHub页面上提出问题.

Maybe Ryan can explain why this was changed, and why computed's are behaving differently than regular observables in this case. You might want to make an issue on the GitHub page.

这篇关于由版本2.2.0中的异常键触发的kickout.js值绑定的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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