我找到了一些使用自动完成功能的代码。现在我想用多个数组添加我的源数据。我怎样才能做到这一点?
var aTags = ["ask", "always", "all", "alright", "one", "foo", "blackberry", "tweet", "force9", "westerners", "sport"];
var bTags = ["aaaaaaa", "bbbbbbbb", "ccccccc", "ddddddddd"];
答案 0 :(得分:0)
你可以merge
这样的两个数组。
var aTags = ["ask","always", "all", "alright", "one", "foo", "blackberry", "tweet","force9", "westerners", "sport"];
var bTags = ["aaaaaaa", "bbbbbbbb", "ccccccc", "ddddddddd"];
var cTags=$.merge( aTags,bTags );
$( "#tags" ).autocomplete({
source: cTags
});

<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<link href="https://ajax.googleapis.com/ajax/libs/jqueryui/1.12.1/themes/base/jquery-ui.css" rel="stylesheet"/>
<script src="https://ajax.googleapis.com/ajax/libs/jqueryui/1.12.1/jquery-ui.js"></script>
<input type='text' title='Tags' id='tags' />
&#13;
答案 1 :(得分:0)
在链接的jsfiddle中,
#selLanguage
已填充了值。
如果我理解正确,
您想要用两个数组的串联替换这些值。
这是working fiddle的相关部分:
$(function() {
var aTags = ["ask", "always", "all", "alright", "one", "foo", "blackberry", "tweet", "force9", "westerners", "sport"];
var bTags = ["aaaaaaa", "bbbbbbbb", "ccccccc", "ddddddddd"];
var $langs = $("#selLanguage");
$langs.empty();
$.each(aTags.concat(bTags), (k, v) => $langs.append($("<option></option>").attr("value", v).text(v)));
$langs.combobox();
});