I am wondering how can I combine 2 sources together using the jquery autocomplete?
What I hope to achieve is having the results "chocolate biscuits", "strawberry biscuits", "peanut biscuits" and so on.. then it will loop to swiss roll and start the flavours all over again: "chocolate swiss roll", "strawberry swiss roll", "peanut swiss roll", etc.
When user type the word: "chocolate", all the food values will appear in the autocomplete. However I can't seem to get the results I want.
Here is my code:
<script>
var food= [
"biscuits",
"swiss roll",
"bread",
"waffle",
"cookies"
];
var flavours= [
"chocolate",
"strawberry",
"peanut",
"cheese",
"green tea",
"vanilla"
];
var mergedResults;
for (i = 0; i < food.length; i++) {
for (j=0; j < flavours.length; j++) {
mergedResults = food[i].concat(flavours[j]);
}
}
$( "#autocomplete" ).autocomplete({
source: mergedResults
});
</script>