我已经搜索了答案,但仍然找不到。我想我做错了什么,但我无法弄清楚它是什么。这是我的预输入代码:
$('.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
});
这是我的 _global.json 文件:
{
"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"]}
]
}
Json 文件不能有其他格式,因为其他一些代码依赖于这种格式。预取不起作用,我想我必须使用过滤器。尝试了我能找到的所有类型的过滤器示例,但似乎没有任何效果。我究竟做错了什么。
ps(当我在 json 文件中省略顶部大括号和关键“项目”时,它都可以正常工作,所以 js. 库和 Hogan 没有问题)
希望可以有人帮帮我。
问候。德克尔