我有http://jsfiddle.net/pF2cF/6/代码有2个问题:1.单击"MyButton"不会转到App.indexController中的clickButton函数2.在文本字段中输入会先触发MyButton点击(如果#1得到解决)
任何人都可以帮助解决它们吗?我确实有使用的解决方法,但我不确定使用时有什么问题.
谢谢!
代码片段如下,在2013年1月14日使用其主分支中的ember.js:
<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");
}
});
Run Code Online (Sandbox Code Playgroud)
Yeh*_*atz 18
你犯了一些小错误.我在JSBin上放了一个工作版本.
不会导致任何失败的文体问题:
index路线.ready方法Application.通常,将启动逻辑放入ApplicationRoute#setupController其中,您也可以访问控制器.index而不是myTemplate.与失败有关的问题:
App.IndexController不是App.indexControllerrender电话指定{ controller: 'indexController' }.它应该是{ controller: 'index' }.| 归档时间: |
|
| 查看次数: |
2963 次 |
| 最近记录: |