我们一直在我们的 Ember 应用程序中使用 Typeahead.js 库(通过这个插件)在 1.10 之前的 Ember 版本上取得了成功,但是升级到 Ember 1.10 给我们带来了问题。
到目前为止,我们已经成功编译了模板,这些模板被传递到 typeahead 组件并将其传递给 typeahead 库,如下所示:
templates: {
// this.get('suggestionTemplate') is a string of handlebars template
suggestion: Handlebars.compile(this.get('suggestionTemplate')),
<other code>
}
但是,这在 Ember 1.10 中不起作用,因为 typeahead.js 在执行这行代码时会引发以下错误:
代码:
$el = $(html.suggestion).append(that.templates.suggestion(suggestion)).data(datasetKey, that.name).data(valueKey, that.displayFn(suggestion)).data(datumKey, suggestion);
错误:
Uncaught TypeError: that.templates.suggestion is not a function
以前that.templates.suggestion
,这是上面第一个代码块中的值,是一个可以传递对象suggestion
并编译实际模板的函数。使用 HTMLBars,that.templates.suggestion
不再是一个函数,而是一个 HTMLBars 对象,所以这段代码不再有效。
在 Ember 1.10 中是否有更好的方法来做同样的事情来匹配之前的行为?