我对Hogan.js和typeahead.js都是新手,所以这个问题可能很愚蠢。
$('.example-twitter-oss .typeahead').typeahead({
name: 'twitter-oss',
prefetch: 'repos.json',
template: [
'<p class="type">{{language}}</p>',
'<p class="name">{{name}}</p>',
'<p class="description">{{description}}</p>'
].join(''),
engine: Hogan
});这就是我如何使用Hogan.js作为模板创建我的typeahead.js实例。现在我想更改我的测试数据:'repos.json',模板仍然是相同的。我猜它是以某种方式缓存的。如何重置我的模板以包含新数据?
我看到hogan有一个compile();和render()方法,但我不知道如何使用它。
我使用的是这两个版本的最新版本。
发布于 2013-07-19 05:47:15
在当前版本的typeahead.js (0.9.3)中,数据集是按其名称属性进行缓存的,因此无法访问bust the cache。所以,如果你有:
$('.example-twitter-oss .typeahead').typeahead({
name: 'twitter-oss',
prefetch: 'repos.json',
template: [
'<p class="type">{{language}}</p>',
'<p class="name">{{name}}</p>',
'<p class="description">{{description}}</p>'
engine: Hogan
});
$('.example-something-different .typeahead').typeahead({
name: 'twitter-oss',
prefetch: 'something_different.json'
});.example-something-different .typeahead不会使用指定的配置,它将使用.example-twitter-oss .typeahead指定的配置,因为它们使用相同的name。这并不直观,它将在下一个版本v0.10中发生变化。但现在,您可以通过使用不同的name来绕过此问题:
$('.example-twitter-oss .typeahead').typeahead({
name: 'twitter-oss',
prefetch: 'repos.json',
template: [
'<p class="type">{{language}}</p>',
'<p class="name">{{name}}</p>',
'<p class="description">{{description}}</p>'
].join(''),
engine: Hogan
});
$('.example-something-different .typeahead').typeahead({
name: 'something different',
prefetch: 'something_different.json'
});https://stackoverflow.com/questions/17732640
复制相似问题