I want to populate tags of jQuery autocomplete from result of .each in jQuery how can I do it any help is appreciated.
My Code:
var availableTags ="";
$(xData.responseXML).SPFilterNode("z:row").each(function() {
var Title = $(this).attr("ows_Title");
var Contact = Title+",";
Contact +=Contact;
availableTags[Contact];
});
the jQuery auto complete requires a variable like bellow:
var availableTags = [
"ActionScript",
"Clojure",
"COBOL",
"Scheme"
];
You need an array. So create the array. Something like this:
var availableTags = [];
$(xData.responseXML).SPFilterNode("z:row").each(function() {
availableTags.push($(this).attr("ows_Title"));
});
//just in case for development purpose
console.log(availableTags);
Or even better:
var availableTags = $(xData.responseXML).SPFilterNode("z:row")
.map(function() {
//**this** is an element of the jquery object
return $(this).attr("ows_Title");}) //returns jquery object
.get(); //converts jquery object to array