如何在ViewModel中获取Kendo UI AutoComplete onKeyUp的值 [英] How to get value of Kendo UI AutoComplete onKeyUp inside ViewModel

查看:128
本文介绍了如何在ViewModel中获取Kendo UI AutoComplete onKeyUp的值的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试根据用户键入获取Kendo UI自动完成的值,以便将查询发送到服务器以过滤结果.更改事件仅触发onBlur,而不触发上/下/按.在这种情况下,数据值更改绑定也似乎不起作用.

I am trying to get the value of a Kendo UI AutoComplete as the user types so I can send that query to the server to filter results. The change event only fires onBlur and not keyup/down/press. The data-value-change binding also appears not to work for this scenario either.

无论如何,是否可以从ViewModel内实现这一目标?

Is there anyway to achieve this from within the ViewModel?

请在 jsFiddle这里 中查看下面的代码. 您会注意到数据值更改适用于原始输入,但不适用于自动完成功能.

Please see the code below as a working jsFiddle here. You will notice the data-value-change works for a vanilla input but not on the autocomplete.

<div id="view">
<input data-value-update="keyup" 
       data-bind="value: inputValue"
       data-placeholder="text input" />

 <input data-role="autocomplete"
        data-placeholder="autocomplete"
        data-value-primitive="true"
        data-text-field="t"
        data-bind="source: data, value: acValue" />

</div> 



var viewModel = kendo.observable(
{
inputValue: '',
acValue: '',
data: new kendo.data.DataSource([
    {name: 'John', age: 20 },
    {name: 'John 1', age: 201 },
    {name: 'John 2', age: 202 },
    {name: 'John 3', age: 203 },
    ]),
onChange: function()
{
  console.log('change');
}
});
viewModel.bind('change', function(e)
           {
              alert(e.field + ' changed to ' + this[e.field]); 
           });
kendo.bind($("#view"), viewModel);

推荐答案

我遇到了同样的问题.

我设法通过具有另一个可观察的属性(仅用于显示目的)来处理它.

I managed to handle it with having another observable property for just display purpose.

但是主要的可观察属性将在每个KeyUp事件上更新.

But main observable property would be updated on every KeyUp event.

$('textarea').keyup(function () {
        viewModel.set("megaViewModel.ProductionNotes", $(this).val());
    });

我知道与主属性绑定时,我们可以在keyup上更新主属性,但这会导致不正确的插入符号行为.

I know we can update Main Property on keyup when binded with main property, but that would cause improper behavior Caret behavior.

这篇关于如何在ViewModel中获取Kendo UI AutoComplete onKeyUp的值的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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