我尝试复制搜索字段,就像它们在emberjs.com上显示的那样,但是由于某种原因,我的代码在输入查询并按 Enter 或单击提交按钮时不断产生以下错误(在 google chrome 中):
Uncaught Error: Nothing handled the event 'MyApp.ApplicationController.doSearch'.
我正在使用的代码可以在http://jsfiddle.net/Mn2yy/查看
有人可以解释为什么会发生此错误以及我需要做什么来解决它吗?
编辑:如果链接断开,这些是代码的相关部分:
搜索页面路径:
MyApp.SearchRoute = Ember.Route.extend({
setupController: function(controller) {
controller.set('searchQuery', this.get('query'));
},
renderTemplate: function() {
this.render('searchpage', { into: 'container' });
}
});
应用控制器:
MyApp.ApplicationController = Ember.Controller.extend({
// the initial value of the `search` property
search: '',
doSearch: function() {
// the current value of the text field
var query = this.get('search');
this.transitionToRoute('search', { query: query });
}
});
和模板:
<script type="text/x-handlebars" data-template-name="container">
<button {{action "doSearch" target="MyApp.ApplicationController"}} rel="tooltip-bottom" title="search" class="icon"><i class="icofont-search"></i></button>
{{view Ember.TextField valueBinding="MyApp.ApplicationController.search" action="MyApp.ApplicationController.doSearch"}}
{{outlet}}
</script>
<script type="text/x-handlebars" data-template-name="searchpage">
<h1>Search</h1>
{{#linkTo "home"}}Homepage{{/linkTo}}
<p>You searched for: "{{searchQuery}}"</p>
</script>