Reputation: 443
I have searched for an answer but still cant find it. I guess I am doing something wrong but i can't figure out what it is. This is my typeahead code:
$('.zoek').typeahead({
name: 'items01',
prefetch: {
url: '/models/_global.json',
ttl: 1,
},
template: '<div id="breed">
<span>{{#lock}}<img src="/assets/img/lock-icon-small.png">{{/lock}}{{^lock}}<img src="/assets/img/empty-icon-small.png">{{/lock}}</span>
<span class="searchresult"><a href="article">{{value}}</a></span>
<span class="searchresult-type"> - {{type}} </span>
<span class="red">{{#popular}} - popular {{/popular}}</span>
<span class="red">{{#new}} - new {{/new}}</span>
</div>',
engine: Hogan
});
And this is my _global.json file:
{
"items": [
{"value":"making claims for ebook subscriptions",
"icon":"download-icon-small.png",
"type":"brochure",
"date":"12-10-2011",
"lock": false,
"popular": false,
"new": true,
"tag": ["ebook","claim"]},
{"value":"Claim discovery & Online Management Suite - English",
"icon":"download-icon-small.png",
"type":"case",
"date":"28-02-2010",
"lock": true,
"popular": false,
"new": false,
"tag": ["claim","online"]},
{"value":"Get access to all online ebook publishers ",
"icon":"download-icon-small.png",
"type":"factsheet",
"date":"17-08-2012",
"lock": false,
"popular": true,
"new": true,
"tag": ["online","ebook"]},
{"value":"Ebook catalogue in swetswise - howto",
"icon":"show-icon-small.png",
"type":"hint",
"date":"08-01-2009",
"lock": true,
"popular": false,
"new": false,
"tag": ["ebook","swetswise"]},
{"value":"Swetswise software improved: you can claim now!",
"icon":"download-icon-small.png",
"type":"press",
"date":"20-08-2002",
"lock": false,
"popular": true,
"new": false,
"tag": ["swetswise","claim"]}
]
}
The Json file can't have an other format because some other code is relying on this format. Prefetch is not working and I guess I have to use a filter. Tried all kind of filter examples i could find but nothing seems to work. What am I doing wrong.
p.s. (When I leave out the top curly brackets and the key "items" in the json file it is all working, so there are no problems with the js. libraries and Hogan)
Hope someonecan help me.
regards. M.dekker
Upvotes: 2
Views: 1589
Reputation: 443
After a good sleep and some thinking and found the answer to my question.
adding the following code in the prefetch block solved my problem:
filter: function(data){
// filter the returned data
return data.items;
}
Upvotes: 3