逗号分隔的自动完成与jquery不工作的javascript json数据
comma separated auto complete with jquery not working with javascript json data
我正在尝试创建一个逗号分隔的自动完成文本字段,该字段的自动完成json数据来自java脚本本身。。请参阅下面的代码:
java脚本数组:
var remark = [
"is under construction",
"is a part of another construction.",
"has acquired other work.",
"Could not source construction."
];
自动完成方法:
$("#remark").bind("keydown", function(event) {
if (event.keyCode === $.ui.keyCode.TAB &&
$(this).data("ui-autocomplete").menu.active) {
event.preventDefault();
}
}).autocomplete({
source: function(request, response) {
$.getJSON(JSON.stringify(remark), { //this line is the issue..
term: extractLast(request.term)
}, response);
},
search: function() {
var term = extractLast(this.value);
if (term.length < 2) {
return false;
}
},
focus: function() {
return false;
},
select: function(event, ui) {
var terms = split(this.value);
terms.pop();
terms.push(ui.item.value);
terms.push("");
this.value = terms.join(",");
return false;
}
});
助手功能:
function split(val) {
return val.split(/,'s*/);
}
function extractLast(term) {
return split(term).pop();
}
CCD_ 1保存自动完成的数据以显示给用户。。。
CCD_ 2正在获取用于自动完成的数据。。功能,但这并不能像aspect ed.那样工作。而当我使用从mysql服务器获取数据时,这是有效的。。但是当我将它与java脚本数组一起使用时,它不起作用。。
任何帮助或建议都会很有帮助。。提前感谢。。。
var remark = [
"is under construction",
"is a part of another construction.",
"has acquired other work.",
"Could not source construction."];
$("#remark").bind("keydown", function (event) {
if (event.keyCode === $.ui.keyCode.TAB && $(this).data("ui-autocomplete").menu.active) {
event.preventDefault();
}
}).autocomplete({
source: remark,
search: function () {
var term = extractLast(this.value);
if (term.length < 2) {
return false;
}
},
focus: function () {
return false;
},
select: function (event, ui) {
var terms = split(this.value);
terms.pop();
terms.push(ui.item.value);
terms.push("");
this.value = terms.join(",");
return false;
}
});
function split(val) {
return val.split(/,'s*/);
}
function extractLast(term) {
return split(term).pop();
}
工作Fiddle
这个链接对我有用http://jsfiddle.net/phpdeveloperrahul/zMWLx/
var masterdata=["abc","pqr","rst"];
$(function() {
function split( val ) {
return val.split( /,'s*/ );
}
function extractLast( term ) {
return split( term ).pop();
}
$( "#TestNames" ).autocomplete({
source: function( request, response ) {
response( $.ui.autocomplete.filter(
masterdata, extractLast( request.term ) ) );
},
select: function( event, ui ) {
// Add the selected term appending to the current values
with a comma
var terms = split( this.value );
// remove the current input
terms.pop();
// add the selected item
terms.push( ui.item.value );
// join all terms with a comma
this.value = terms.join( ", " );
return false;
},
focus: function() {
// prevent value inserted on focus when navigating the drop
down list
return false;
}
});
});
相关文章:
- PHP/AAJAX阻止jquery工作
- Chrome扩展和Chome浏览器中的Jquery工作方式不同
- 2次点击事件不会'我在jquery工作
- 使用 href=“#” JQuery 工作,但使用 href=“page.jsp” 不起作用
- 迭代 javascript 对象无法通过 jQuery 工作
- 让简单的Javascript / jQuery工作(Ariel Flesler的ScrollTo)
- 更新面板阻止 jquery 工作
- Jquery工作,但只是暂时的
- 一个jQuery工作,两个不工作
- 当我使用AngularJS部分时,如何让JQuery工作
- 为什么不;我的jquery工作(使用延迟、hasclass、addclass、removeclass、keyUp、key
- jQuery工作不正常
- 我有一个JQuery工作,但小越野车
- :has() jquery工作不正常
- JQuery工作得太快了
- 如果一个输入单选被选中,改变父元素'的颜色:不能'使它与jQuery工作
- Chrome扩展:访问DOM的弹出.html和让jQuery工作
- 如何使下拉jQuery工作
- 尝试使jquery工作
- RegEx不与我的jQuery工作