return FALSE; $r = well_tag_thread__update(array('id' => $id), $update); return $r; } function well_tag_thread_find($tagid, $page, $pagesize) { $arr = well_tag_thread__find(array('tagid' => $tagid), array('id' => -1), $page, $pagesize); return $arr; } function well_tag_thread_find_by_tid($tid, $page, $pagesize) { $arr = well_tag_thread__find(array('tid' => $tid), array(), $page, $pagesize); return $arr; } ?>javascript - Cancel action in Ember TextView with escape key - Stack Overflow
最新消息:雨落星辰是一个专注网站SEO优化、网站SEO诊断、搜索引擎研究、网络营销推广、网站策划运营及站长类的自媒体原创博客

javascript - Cancel action in Ember TextView with escape key - Stack Overflow

programmeradmin2浏览0评论

How can I make Ember trigger a controller action when the user presses the escape key in an input field?

Given the following application code:

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");
    }
  }
});

And the following 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>

I would expect the cancel action in the controller to be triggered, but what I get is an error: Property 'cancel' of object [object Object] is not a function.

Here's a JSBin with the above code to illustrate. How can I make this work?

How can I make Ember trigger a controller action when the user presses the escape key in an input field?

Given the following application code:

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");
    }
  }
});

And the following 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>

I would expect the cancel action in the controller to be triggered, but what I get is an error: Property 'cancel' of object [object Object] is not a function.

Here's a JSBin with the above code to illustrate. How can I make this work?

Share Improve this question asked Nov 12, 2013 at 10:05 Martin SolliMartin Solli 4303 silver badges8 bronze badges
Add a ment  | 

1 Answer 1

Reset to default 11

It's not very documented, but seeing the code... https://github./emberjs/ember.js/blob/v1.1.2/packages/ember-handlebars/lib/controls/text_support.js#L106-L117

You should define you handlebars like this

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

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

发布评论

评论列表(0)

  1. 暂无评论