多数组添加自动完成 [英] Multiple array add in autocomplete
本文介绍了多数组添加自动完成的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我想在自动完成中添加多个数组.我已经添加了aTags
,但是如何添加bTags
?
I want to add multiple array in autocomplete. I have added aTags
but how can I add bTags
?
var aTags = ["ask", "always", "all", "alright", "one", "foo", "blackberry", "tweet", "force9", "westerners", "sport"];
var bTags = ["aaaaaaa", "bbbbbbbb", "ccccccc", "ddddddddd"];
$("#tags").autocomplete({
source: aTags,
response: function(e, result) {
if (!result.content.length) {
console.log('No matches!');
jQuery('#messag').html("Not match...").show();
} else {
jQuery('#messag').hide();
}
}
});
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<script src="https://code.jquery.com/ui/1.12.0/jquery-ui.min.js"></script>
<link rel="stylesheet" href="https://code.jquery.com/ui/1.12.0/themes/smoothness/jquery-ui.css" />
<input type='text' title='Tags' id='tags' />
<span id="messag"></span>
推荐答案
You can use the Array.prototype.concat() function to achieve this.
您需要将source: aTags
更改为source: aTags.concat(bTags)
var aTags = ["ask", "always", "all", "alright", "one", "foo", "blackberry", "tweet", "force9", "westerners", "sport"];
var bTags = ["aaaaaaa", "bbbbbbbb", "ccccccc", "ddddddddd"];
$("#tags").autocomplete({
source: aTags.concat(bTags),
response: function(e, result) {
if (!result.content.length) {
console.log('No matches!');
jQuery('#messag').html("Not match...").show();
} else {
jQuery('#messag').hide();
}
}
});
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<script src="https://code.jquery.com/ui/1.12.0/jquery-ui.min.js"></script>
<link rel="stylesheet" href="https://code.jquery.com/ui/1.12.0/themes/smoothness/jquery-ui.css" />
<input type='text' title='Tags' id='tags' />
<span id="messag"></span>
这篇关于多数组添加自动完成的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文