I am working on a website that auto populates search result in a table after user entered some text in the input text box (similar to google instant search).

我正在开发一个网站,在用户在输入文本框(类似于谷歌即时搜索)中输入一些文本后自动将搜索结果填充到表格中。

I managed to get knockout js to update view model as user enters information by adding

当用户通过添加输入信息时,我设法让knockout js更新视图模型

valueUpdate: 'afterkeydown'

valueUpdate:“afterkeydown”

into my data-bind attribute, however, I also need to handle the case where user right click and paste some text into the textbox so I tried:

然而,在我的数据绑定属性中,我还需要处理用户右击并将一些文本粘贴到文本框中的情况,所以我尝试了:

valueUpdate: ['afterkeydown','mouseup']

valueUpdate:[' afterkeydown ',' mouseup ']

but that didn't work and when I tried to read the value of the text box through the view model I kept getting the old value until I tab out of the input text box.

但这不起作用,当我试图通过视图模型读取文本框的值时,我一直在获取旧值,直到我从输入文本框中跳出来。

Anyone know how can I fix this?

有人知道我怎么修复吗?

Oscar

奥斯卡

2 个解决方案

#1


24

You can use valueUpdate:'input'. I have testet it to work in Opera, Firefox and Chrome. I'm on a Linux box, so I can't test it in IE. Check this fiddle

您可以使用valueUpdate:“输入”。我在Opera、Firefox和Chrome上都有测试。我在一个Linux盒子上,所以我不能在IE中测试它。检查这个小提琴

UPDATE: I have now testet it in IE8, and it doesn't work. But using the following seems to work.

更新:我现在在IE8中测试了它,但是它不工作。但是使用以下方法似乎是有效的。

valueUpdate:['afterkeydown','propertychange','input']

Thanks to Michael Best for his comment about this :) I have updated the fiddle

感谢迈克尔·贝斯特的评论:)我更新了小提琴

UPDATE okt 2014: As kzh mention in a comment below, in one of the later versions of Knockout.js the textInput binding was added. This binding handles this scenario and has build in browser quirks handling http://knockoutjs.com/documentation/textinput-binding.html

更新okt 2014:正如kzh在下面的评论中提到的,在Knockout的一个后续版本中。添加了textInput绑定。此绑定处理此场景,并具有内置浏览器怪癖,处理http://knockoutjs.com/documentation/textinput-binding.html

更多相关文章

  1. 使用javascript或jquery将具有相同id的多个文本区域内容复制到剪
  2. 五十行javascript代码实现简单的双向数据绑定
  3. 在内容可编辑DIV中的选定文本周围包装bb代码
  4. Bootstrap面板:同一行上的文本和加号
  5. Knockout.js - 在通过observable设置值时阻止更改事件绑定
  6. jquery 更改angularJS input 内容导致绑定失效的解决办法
  7. 使用HTML或Javascript替换网页上的文本
  8. 在Internet Explorer中使用sprited按钮和selection.createRange()
  9. 可编辑div中的文本计数和子字符串

随机推荐

  1. HTML5之MSE标准为移动端的直播应用带来超
  2. 手机端阻止页面滑动
  3. js去除字符串中所有html标签及&nbsp符号
  4. HTML5中window.postMessage,在两个页面之
  5. 如何集中无序列表?
  6. 如何使用一个锚标记打开多个链接
  7. 我正在尝试使用带有post方法的AJAX将用户
  8. 如何只用HTML和CSS构建一个特殊的多边形(
  9. 【HTML】让标签文本自动换行
  10. 在Makefile.am中添加make install 的安装