使用转义键在余烬文本视图中取消操作

Cancel action in Ember TextView with escape key

本文关键字:视图 取消 操作 文本 余烬 转义      更新时间:2023-09-26
如何

让 Ember 在用户按下输入字段中的转义键时触发控制器操作?

给定以下应用程序代码:

App = Ember.Application.create();
App.IndexRoute = Ember.Route.extend({
  model: function () {
    return {foo: "bar"};
  }
});
App.IndexController = Ember.ObjectController.extend({
  actions: {
    done: function () {
      console.log("done");
    },
    cancel: function () {
      console.log("cancel");
    }
  }
});

和以下 HTML:

<body>
  <script type="text/x-handlebars" data-template-name="application">
    {{outlet}}
  </script>
  <script type="text/x-handlebars" data-template-name="index">
    {{input value=foo action="done" cancel="cancel"}}
  </script>
</body>

我希望触发控制器中的取消操作,但我得到的是一个错误:Property 'cancel' of object [object Object] is not a function.

下面是一个带有上述代码的 JSBin。我怎样才能做到这一点?

它不是很文档化,但看到代码...https://github.com/emberjs/ember.js/blob/v1.1.2/packages/ember-handlebars/lib/controls/text_support.js#L106-L117

你应该像这样定义你的车把

{{input value=foo enter='done' escape-press='cancel'}}

杰斯宾 http://jsbin.com/ObucELO/1/edit