使用转义键取消Ember TextView中的操作

时间:2013-11-12 10:05:34

标签: javascript ember.js

当用户在输入字段中按下转义键时,如何使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

Here's a JSBin用上面的代码来说明。我怎样才能做到这一点?

1 个答案:

答案 0 :(得分:11)

它没有很好的记录,但看到代码...... 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'}}

JsBin http://jsbin.com/ObucELO/1/edit

相关问题