gpt4 book ai didi

jquery - 为什么 jquery ui 自动完成功能放弃对这些功能的支持?

转载 作者:行者123 更新时间:2023-12-03 22:50:39 24 4
gpt4 key购买 nike

jquery UI 团队有一个 blog on how to replace the legacy autocomplete and justifies that it can replicate all of the old features and options 。根据我的测试,我认为它们无法复制:

  1. selectFirst 如果您有远程数据源
  2. selectFirstmustMatch(如果您使用multiple: true)

我明白了this questions on how to replicate some of the legacy autocomplete选项来自 this plugin ,并且有一个选定的答案,但它没有解决这些情况。

jquery ui folks have an example of replicating selectFirst in the new autocomplete ,但除非我弄错了,否则它仅适用于本地数据源(不适用于远程数据源,因为在调用事件之前通常不会填写菜单)。

我是否遗漏了某些内容,或者 jquery ui 自动完成功能根本不支持这些场景??

最佳答案

实际上支持这些场景,但是您必须扩展 ui.autocomplete 小部件才能实现所需的行为。实现 selectFirst 功能的快速示例:

$.widget( "ui.autocomplete2", $.ui.autocomplete, {
_renderMenu: function( ul, items ) {
var self = this;
$.each( items, function( index, item ) {
self._renderItem( ul, item );
});
// setTimeout is needed because jQueryUI automaticaly removes
// active item just after menu rendering
setTimeout( function(){
self.menu.activate(
// fake event object. Needed to avoid jQueryUI error
// (unsafe property access)
{'type':'fake'},
ul.find(':first') );
}, 1);
}
});

注意:始终检查新的小部件是否仍然与新版本的 jQuery UI 兼容!

更新:mustMatch 实现示例可在此处找到:http://jqueryui.com/demos/autocomplete/combobox.html

关于jquery - 为什么 jquery ui 自动完成功能放弃对这些功能的支持?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/5057965/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com