我正在尝试使用 ember-cli 重现 Ember-TodoMVC。我被这部分困住了。
我创建了一个这样的视图:
app/views/action-edit.coffee
ActionEditView = Ember.TextField.extend
didInsertElement: -> @$().focus()
`export default ActionEditView`
当我直接在 Emblem 模板中使用它时,例如view "action-view"
,它工作正常:呈现文本字段。
但是 emberjs.com/guides 建议创建一个助手来渲染视图。
我在 ember-cli 网站上发现了这句话:“请记住,您必须通过导出 makeBoundHelper 来注册您的助手”。经过一段时间努力理解 ES6 模块是如何工作的,我最终得到了这段代码,它不会产生任何 JS 错误:
app/helpers/action-edit.coffee
`import ActionEditView from 'loltodo/views/action-edit'`
`export default Ember.Handlebars.makeBoundHelper(ActionEditView)`
当我在 Emblem 模板中这样使用它时action-edit
,Ember 在浏览器控制台中输出:
[✓] helper:action-edit ......................... loltodo /helpers/action-edit 供应商/ember/ember.js:3521
所以我假设助手得到了很好的连接。
问题是它呈现空白!
我也试过这个:
app/helpers/action-edit.coffee
`import ActionEditView from 'loltodo/views/action-edit'`
`export default Ember.Handlebars.helper('action-edit', ActionEditView)`
这会导致此行中出现错误“未定义不是函数” 。
所以问题是:我如何创建一个使用 ember-cli 渲染视图的助手来重现Ember-TodoMVC 教程的这一步?