如何在Ember.js中使用jQuery获取id?

时间:2012-08-05 07:35:25

标签: javascript jquery ember.js

如何以这样的方式获取按钮的动作:

<script type="text/x-handlebars">
    {{#view Ember.Button target="Welcome.booksController" action="loadBooks" id="butt_logger"}}
        Load Books
    {{/view}}
</script>

在js文件中

$(document).ready( function () {
    $('button#butt_logger').click(function(){
        console.log("Button was Clicked");
    });
});

Welcome.booksController = Ember.ArrayController.create({
content: [],
loadBooks: function(){
    console.log("Button was Clicked");
            //any script
    }
});

它们都不起作用(( 我需要建议。 感谢。

1 个答案:

答案 0 :(得分:1)

正如您在Ember.Button source code中看到的那样:

Ember.deprecate("Ember.Button is deprecated and will be removed from future releases.
Consider using the {{action}} helper.");

使用{{action}}帮助器,您的模板将如下所示:

<script type="text/x-handlebars">
  <button {{action loadBooks target="Welcome.booksController" }} id="butt_logger">Load books</button>
</script>