相关疑难解决方法(0)

使用Hogan迁移到Typeahead 0.10+

我已经将Typeahead 0.9.3与Hogan 2一起使用了一段时间,而且设置非常简单.

在0.9.3我做了类似的事情:

$('input.search-query').typeahead([
     {
         name:     "pages"
        ,local:    localSuggestions
        ,template: '<div class="tt-suggest-page">{{value}}</div>'
        ,engine:   Hogan
    }
]);
Run Code Online (Sandbox Code Playgroud)

根据迁移指南0.10 "现在需要预编译模板",所以在0.10.3我正在尝试:

$('input.search-query').typeahead(null, {
     name:     "pages"
    ,source:   taSourceLocal.ttAdapter()
    ,templates: {
         suggestion: Hogan.compile('<div class="tt-suggest-page">{{value}}</div>')
     }
});
Run Code Online (Sandbox Code Playgroud)

但它不起作用.我收到一个错误:Uncaught TypeError: object is not a function

如果还有另一个极简主义模板引擎可以工作,我也会考虑它,但它必须很小.我不想添加像Handlebars这样的大文件或像Underscore这样的整个库.

有任何想法吗?TIA!

javascript template-engine hogan.js typeahead.js twitter-typeahead

4
推荐指数
1
解决办法
1015
查看次数