我想我可能误解了 Ember 连接路由、 View 和模板的方式,但我无法弄清楚以下结果会导致错误:
Uncaught Error: Nothing handled the event 'createUser'.
我的文件如下:
javascripts/router.js.coffee
App.Router.map ->
@resource 'account', ->
@route 'index', path: '/'
javascripts/routes/account_router.js.coffee
App.AccountRoutes = Ember.Route.extend
model: -> App.User.find()
javascripts/controllers/account_controller.js.coffee
App.AccountController = Ember.ObjectController.extend
createUser: ->
App.User.createRecord
field1: @get('field1')
/ etc
javascripts/views/account_view.js.coffee
App.AccountView = Ember.View.extend
templateName: 'account'
javascripts/templates/account/index.emblem
form.form submit="createUser"
/ fields
最佳答案
我认为您缺少 actions
哈希值。
模板内的操作,例如:
<script type="text/x-handlebars" id="foo">
<div {{action "doFoo"}}>Click here</div>
</script>
需要出现在相应的 Controller 或路由中的操作对象内:
App.FooController = Ember.ObjectController.extend({
actions: {
doFoo: function() {
alert('Foo');
}
// ... more actions here
}
});
就您的情况而言,我认为您需要更新为以下内容:
App.AccountController = Ember.ObjectController.extend
actions:
createUser: ->
App.User.createRecord
field1: @get('field1')
关于javascript - Ember.js/Emblem.js 未捕获错误 : Nothing handled the event 'createUser' ,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/19645812/