今天我尝试将我的应用程序更新到ember 1.7.0,但我注意到视图中的操作处理程序停止被调用。
我的观点定义如下:
// Ember view for the project partial
App.ProjectThumbnailView = Ember.View.extend({
templateName: 'partials/_project',
didInsertElement: function() {...},
/**
* Handles the event when the 'feature project' button is pressed
* @param {Project} project The project to be featured
*/
featureProject: function() {
var project = this.get('context');
project.toggleProperty('featured');
project.toggleProperty('abilities.feature');
project.toggleProperty('abilities.unfeature');
project.feature()
.then(
function() {},
function(error) {
project.toggleProperty('featured');
project.toggleProperty('abilities.feature');
project.toggleProperty('abilities.unfeature');
App.set('error', {
message: I18n.t('error_message_generic_server')
});
}
);
}
});
模板partials/project.hbs包含以下按钮来调用操作:
<button class="btn btn-mini btn-primary right-top" {{action 'featureProject' target='view'}}><i class="icon-star"></i> {{unbound i18n 'feature'}}</button>
我还尝试将featureProject操作放入操作哈希中,但没有成功。
这在ember版本1.6.0及之前的版本中曾经非常适用。我缺什么了吗。
谢谢。
您应该在actions
散列中执行操作。Ember 1.7.0删除了对在控制器根对象中查找操作的支持。这已经被弃用一段时间了。
// Ember view for the project partial
App.ProjectThumbnailView = Ember.View.extend({
actions: {
/**
* Handles the event when the 'feature project' button is pressed
* @param {Project} project The project to be featured
*/
featureProject: function() {
var project = this.get('context');
// blah blah
}
}
});