I am using Typeahead Bootstrap in a form field (with a WP framework).
I have a .json file stored in my root, which I can grab using prefetch:
prefetch: {
url: '
../json/test.json',
ttl: 1
}
menu works just fine. Now, let’s say I dont want to use prefetch, but load the datum in a local json array.
I have the same json file that looks like:
[{"title":"Title 1","content":"Loopty loos"},{"title":"Title 2","content":"Diddly Bones"}]
If I load that directly into the new Bloodhound class:
local: [{"title":"Title 1","content":"Loopty loos"},{"title":"Title 2","content":"Diddly Bones"}]
again, works like a charm. However, if I try to load the same data in as a variable, rather than explicitly written:
jsonObject = [{“title”:”Title 1″,”content”:”Loopty loos”},{“title”:”Title 2″,”content”:”Diddly Bones”}]
var content = new Bloodhound({
datumTokenizer: function (d) {
return Bloodhound.tokenizers.whitespace(d.content);
},
local: jsonObject
...
It doesn’t work. This seems like it’s something simple and I am just completely missing it.
Full clarification, I am querying the wp database, and with that result set creating the json file and writing it to the test directory, then passing it to a .js file using wp_localize_script.
After declaring Bloodhound object, try to initialize the object.
content.initialize();