3

KendoUI Autocomplete 不允许我连续两次选择同一个项目。如果我选择一个项目,然后选择另一个项目,它当然会起作用,但不是背靠背。

通过放置select方法this.trigger('change'),如果您单击列表本身中的项目,它将起作用,但是如果您输入相同的内容并按Enter,则不会触发更改事件。kendoAutoComplete({})

  1. 键入 Anne,单击它(注意它会将其添加到正文中(更改事件已触发))
  2. 再试一次(没有任何反应)

只是一些示例代码:jsFiddle 示例

var autoComplete = $("#input").kendoAutoComplete({
    // other methods...
    select: function (e) {
        console.log('---SELECT---');
        
        // this will work if we select the same thing and SELECT the item 
        // from the the dropdown list,
        //  ** but if we push ENTER, it won't trigger this
        
        //this.trigger('change'); // <--
    },
    change : function (e) {
        console.log(' >> CHANGE');
        $('body').append('<br>' + this.value());
    }
});
4

2 回答 2

1

有点奇怪,但文档说: Change :“当用户更改小部件的值时触发。” 这意味着一旦您输入 Anne 并按下 Enter 控件的值设置为“Anne”,一旦您再次输入 Anne 并按下 Enter 值仍然相同,因此没有更改没有事件。通过将触发器放入选择中,这对我来说听起来是一个不同的事件>选择时触发。

于 2013-05-21T16:54:20.213 回答
0

回到这个问题后,只需将 kendoAutoComplete 的值设为空即可解决问题。

例子:

$('#kendoID').data('kendoAutoComplete').value('');

// I have this at the end of the .change() event
// Lets you keep adding the same item
于 2014-04-08T20:30:03.123 回答