Reputation: 815
I have http://jsfiddle.net/pF2cF/6/ code with 2 problems: 1. click "MyButton" doesn't go to clickButton function in App.indexController 2. enter in the text field will trigger MyButton click first (if #1 get solved)
Can anyone help to solve them? I do have a workaround for by using , but I'm not sure what's wrong with using.
Thanks!
The code snippets are as following, using ember.js from its master branch on 01/14/2013:
<script type="text/x-handlebars" data-template-name="myTemplate">
<button {{action clickButton target="App.indexController"}} >MyButton1</button>
{{view App.MyView placeholder="Input something 1 and enter"}}
</script>
App = Em.Application.create({
ready: function () {
}
});
App.Router.map(function () {
this.route("index", { path: "/" }); //master 01142013 syntax
});
App.IndexRoute = Ember.Route.extend({
renderTemplate: function () {
this.render('myTemplate', {controller: 'indexController'});
}
});
App.indexController = Ember.Controller.extend({
clickButton: function () {
alert("clickButton");
}
});
App.MyView = Em.TextField.extend({
insertNewline: function (evt) {
alert("enter pressed");
}
});
Upvotes: 5
Views: 3019
Reputation: 28703
You made a number of small errors. I have put a working version on JSBin.
Stylistic issues that did not cause any failures:
index
routes.ready
method on Application
. In general, put startup logic in ApplicationRoute#setupController
, where you will also have access to controllers.index
rather than myTemplate
.Issues related to the failures:
App.IndexController
not App.indexController
render
call specifies { controller: 'indexController' }
. It should be { controller: 'index' }
.Upvotes: 18