当用户在输入字段中按下转义键时,如何让 Ember 触发 Controller 操作?
给定以下应用程序代码:
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>
我希望 Controller 中的取消操作被触发,但我得到的是一个错误:Property 'cancel' of object [object Object] is not a function
。
Here's a JSBin用上面的代码来说明。我怎样才能使它工作?
最佳答案
它的文档不是很多,但是看到代码... https://github.com/emberjs/ember.js/blob/v1.1.2/packages/ember-handlebars/lib/controls/text_support.js#L106-L117
你应该这样定义你的 Handlebars
{{input value=foo enter='done' escape-press='cancel'}}
关于javascript - 使用转义键取消 Ember TextView 中的操作,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/19926191/