I have an array of items from the database.
`$this->ingredientsHistory` is the variable that contains the array.
I want to convert this into a javascript var that will hold them all and I can then use them in the autocomplete jquery UI function.
I've tried var ingredients = <?php echo json_encode($this->ingredientsHistory); ?>
This is an example of a print_r($this->ingredientsHistory);
output...
Array ( [0] => Array ( [name] => oranges ) [1] => Array ( [name] => chicken ) )
Any help would be appreciated.
Edit - more information:
$(function() {
var ingredients = <?php echo json_encode($this->ingredientsHistory); ?>;
console.log(ingredients);
//this is the default tags that jquery gives me - i need to turn ingredients into something similar.
var availableTags = [
"ActionScript",
"AppleScript",
"Asp",
"BASIC",
"C",
"C++",
"Clojure",
"COBOL",
"ColdFusion",
"Erlang",
"Fortran",
"Groovy",
"Haskell",
"Java",
"JavaScript",
"Lisp",
"Perl",
"PHP",
"Python",
"Ruby",
"Scala",
"Scheme"
];
$( "#tags" ).autocomplete({
source: ingredients
});
});
var ingredients = <?php echo json_encode($this->ingredientsHistory); ?>;
– Marcel Gwerder Apr 21 '13 at 16:06