小编Mar*_*lli的帖子

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

当用户在输入字段中按下转义键时,如何使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");
    }
  }
});
Run Code Online (Sandbox Code Playgroud)

以下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>
Run Code Online (Sandbox Code Playgroud)

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

这是一个带有上面代码的JSBin来说明.我怎样才能做到这一点?

javascript ember.js

6
推荐指数
1
解决办法
1269
查看次数

标签 统计

ember.js ×1

javascript ×1