任何人都可以帮助我在emberJS上{{action}}获取元素吗?
离。
// application.hbs
<a href="#" {{action 'displayLinks'}}>Get me</a>
// app.js
App.IndexRoute = Ember.Route.extend({
actions: {
displayLinks: function() {
// returns an object with, no element properties
console.log(this);
}
}
});
答案 0 :(得分:1)
// application.hbs
<a href="#" id="elementId" {{action 'displayLinks' 'elementId'}}>Get me</a>
// app.js
App.ApplicationRoute = Ember.Route.extend({
actions: {
displayLinks: function(id) {
console.log($("#" + id)[0]);
}
}
});