问题描述
这里我在PrimeFaces 5.1中使用p:autoComplete
标记,但是我无法从建议列表中删除第一个突出显示/选择的项目.我该如何删除呢?
Here I am using p:autoComplete
tag in PrimeFaces 5.1, but I can't remove first highlighted/selected item from the suggestions list. How I can remove this ?
推荐答案
由于您的问题"来自特定的 line
,
Since your "problem" comes from this particular line
,
firstItem.addClass('ui-state-highlight');
这里是什么情况,当建议准备好显示出来时,脚本会突出显示列表的第一项,因此对于您而言,您只需取消突出显示"该项即可.
What happens here is when the suggestions are ready to show up the script highlights the first item of the list, so in your case you would just "unhighlight" that item.
我创建了一个小函数,可以对您拥有的每个自动完成功能执行此操作,您可以在document.ready
或任何您认为合适的地方调用它:
I have created a small function that would do that on every AutoComplete you have, you can call it in your document.ready
or where ever you see suitable:
function removeHighlightedFirstItem() {
var oldAutoCompleteShowSuggestions = PrimeFaces.widget.AutoComplete.prototype.showSuggestions;
PrimeFaces.widget.AutoComplete.prototype.showSuggestions = function(query) {
//calling original ShowSuggestions
oldAutoCompleteShowSuggestions.apply(this, [query]);
//after ShowSuggestions
//remove first item highlight
var firstItem = this.items.eq(0);
firstItem.removeClass('ui-state-highlight');
}
}
结果如下:
注意:通过向组件添加autoHighlight = "false"
属性,您所请求的功能可用于5.1.5、5.0.14和5.2.
Note: The feature you are requesting is available for 5.1.5, 5.0.14 and 5.2 by adding the autoHighlight = "false"
attribute to the component.
这篇关于取消突出显示“自动完成"中的第一个突出显示的项目的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!