javascript - emberjs 没有处理该事件

标签 javascript jquery ember.js

我尝试复制搜索字段,就像它们在 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' });
    }
});

应用程序 Controller :

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>

最佳答案

您不应该对绑定(bind)、目标等使用绝对路径,例如 MyApp.ApplicationController.search

由于您在应用程序 Controller 上声明了 search 属性和 doSearch 操作,因此只需键入:{{view Ember.TextField valueBinding="search “行动=“doSearch”}}

关于javascript - emberjs 没有处理该事件,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/16012309/

相关文章:

javascript - li.selected 菜单有问题

javascript - 将 Google 折线图放入 Leaflet 弹出窗口中

javascript - 单击添加/删除隐藏的溢出

javascript - 模型在 Ember 中解析后,从路线触发 Controller 上的操作

javascript - Chrome ajax 请求陷入待处理状态

javascript - 尝试在 PHP 中调用 jQuery - 不起作用?

javascript - Jquery 更新下面的 CSS

javascript - 修改更改击键文字的代码以在 contenteditable 而不是 textarea 中工作

javascript - 使用 ember 渲染助手时无法保存模型

javascript - EmberJS 2.0 如何避免路线上的动态段始终未定义?