大佬教程收集整理的这篇文章主要介绍了jquery Autcomplete如果有源匹配,我怎么能总是显示renderMenu?,大佬教程大佬觉得挺不错的,现在分享给大家,也给大家做个参考。
var thing = $("#thing").autocomplete({ minLength: 0,source: myarray }) // Override the Render Menu thing.data("autocomplete")._renderMenu= function(ul,items) { var self = this; $.each( items,function( index,item ) { self._renderItem( ul,item ); }); // Adder ul.append( "<a class='Helper'>Add <b>\"" + this.term + "\"</b> as a new item</a>") }
问题是这个HelPER仅在自动填充与myarray至少有1次搜索匹配时显示.如何在用户聚焦时始终显示菜单?
谢谢
/* Override the _response function to always open the suggestions menu: */ thing.data("autocomplete")._response = function(content) { if (!this.options.disabled) { this._trigger("open"); content = this._normalize(content); this._suggest(content); } this.pending--; if (!this.pending) { this.element.removeClass("ui-autocomplete-loading"); } };
这应该有效,但我将继续寻找使用标准API的解决方案.
var thing = $("#thing").autocomplete({ minLength: 0,/* Use a source function instead of the array */ source: function(request,responsE) { var result = myArray.slice(0); /* Filter the array normally... */ result = $.ui.autocomplete.filter(result,request.term); /* Add a placeholder result that we can process later */ result.push({ value: request.term,isPlaceholder: true }); response(result); } }).focus(function() { $(this).autocomplete("search",this.value); }); var renderItem = thing.data("autocomplete")._renderItem; /* Override the _renderItem function to display the placeholder item */ thing.data("autocomplete")._renderItem = function(ul,item) { if (item.isPlaceholder) { return $("<li>") .data("item.autocomplete",item) .append("<a class='Helper'>Add <b>\"" + item.value + "\"</b> as a new item</a>") .appendTo(ul); } else { renderItem(ul,item); } };
我个人会采用这种解决方案,因为它的侵入性较小.
以上是大佬教程为你收集整理的jquery Autcomplete如果有源匹配,我怎么能总是显示renderMenu?全部内容,希望文章能够帮你解决jquery Autcomplete如果有源匹配,我怎么能总是显示renderMenu?所遇到的程序开发问题。
如果觉得大佬教程网站内容还不错,欢迎将大佬教程推荐给程序员好友。
本图文内容来源于网友网络收集整理提供,作为学习参考使用,版权属于原作者。
如您有任何意见或建议可联系处理。小编QQ:384754419,请注明来意。