Want to call controller action from view in EmberJS? Here another solution based on the example by albertjan for the case you have to perform some logic in your View and afterwards delegate to your controller.
1 2 3 |
<script type="text/x-handlebars" data-template-name="index"> <button {{action submit target="view"}} >Sumbit</button> </script> |
View:
1 2 3 4 5 6 7 |
App.ThingView = Ember.View.extend({ submit : function(){ //do the view part of your logic var object = //do whatever you may need this.get("controller").send("submitInController", object); //you do not have to send object, if you do not need to } }); |
Controller:
1 2 3 4 5 |
App.ThingController = Em.ObjectController.extend({ submitInController: function(model) { // do the controller part of your logic } }); |
If you like this question & answer and want to contribute, then write your question & answer and email to freewebmentor[@]gmail.com. Your question and answer will appear on FreeWebMentor.com and help other developers.