1

如何以如下方式获取按钮的操作:

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

他们两个都不起作用((我需要建议。谢谢。

4

1 回答 1

1

正如您在Ember.Button 源代码中看到的:

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>
于 2012-08-05T12:26:30.657 回答