2012-08-05 58 views
1

如何获得按钮的行动方式是这样的:如何在Ember.js中使用jQuery获取元素ID?

<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

As你可以在Ember.Button source code看到:

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

使用{{行动}}帮手,你的模板将是这样的:

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