JQuery的自动完成。如果无法找到项目,显示和QUOT; preSS Enter键插入自动完成"? [英] JQuery Autocomplete. If item cannot be found, display "Press Enter to insert into autocomplete"?
问题描述
我做怎样的一个标签,自动完成组合的。
I am doing kind of a tag-autocomplete combo.
所以基本上,当用户进入一个没有自动完成选项的查询,即AAA,我想自动完成,以砸下来,并显示preSS'回车'创造'AAA'的标签。
So basically when user enters a query that has no autocomplete options, i.e "aaa", I want autocomplete to drop down and display "Press 'Enter' to create a tag for 'aaa'. "
我无法找到的文档(我想这需要我做一些黑客行为,但在这样做之前,我想看看是否有人做这个补丁。)
I can't find anything on the docs (I suppose this requires me to do some hacking, but before doing so, I wanna see if anyone has done a patch for this.)
编辑:
我已经开始在源$ C $ C工作,这是我有:
I have began working on the source code and this is what I have:
$.ui.autocomplete.prototype._response= function( content ) {
/* BUG: when the user clicks "Press Enter to this tag",
* the tag "Press enter to create this tag"
* gets created
*/
console.log(content);
if (content.length == 0) {
content = [{ 'label': "Press Enter to create this tag.", "value": -1 }];
}
if ( !this.options.disabled && content && content.length ) {
content = this._normalize( content );
this._suggest( content );
this._trigger( "open" );
} else {
this.close();
}
this.pending--;
if ( !this.pending ) {
this.element.removeClass( "ui-autocomplete-loading" );
}
};
这工作正常。然而,当,当用户点击preSS输入到这个标签,标签preSS输入来创建此标签被创建。如何解决这个原来的查询?
This works fine. However, when the when the user clicks "Press Enter to this tag", the tag "Press enter to create this tag" gets created. How do I fix this to the original query?
推荐答案
我不知道你如何让你自动完成的结果,但如果如你得到它的$ .getJSON()调用,填充组合的项目根据其结果(不只是给调用的结果直到控制)可以检查是否result.length == 0,如果是的话,加入其他的东西(像元件说preSS输入创建)来组合。
I don't know how you get you're autocomplete results, but if for example you're getting it in a $.getJSON() call, and filling the combo's items based on the result (and not just giving the result of the call straight to the control) you could check whether the result.length == 0, and if so, add something else (like an element saying "Press Enter to create") to the combo.
请表现出一定的code,如果你想要更多的precise答案!
Please show some code, if you want more precise answer!
这篇关于JQuery的自动完成。如果无法找到项目,显示和QUOT; preSS Enter键插入自动完成"?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!