我正在尝试过渡到新创建的记录。我可以创建它,填写并保存在服务器上,但是当涉及到this.transitionToRoute( 'app', this.get( 'content' ) );
控制台错误时:
未捕获的错误:断言失败:您正在尝试查找未定义的控制器,并且 Ember 不知道该控制器的模型。
这不是路由的控制器,因此您必须显式定义控制器 (WEM.AppsCreateAppController) 或将模型作为第二个参数传递给controllerFor
,以便 Ember 知道要为您创建哪种类型的控制器。
我明白错误告诉我什么,只是不确定我哪里出错了。这是(我认为是)相关代码:
WEM.CreateAppController = Ember.ObjectController.extend({
startEditing: function() {
console.log( 'start' );
this.transaction = this.get( 'store' ).transaction();
this.set( 'content', this.transaction.createRecord( WEM.App, {} ) );
},
stopEditing: function() {
console.log( 'stop' );
if ( this.transaction ) {
this.transaction.rollback();
this.transaction = null;
}
},
save: function() {
console.log( 'save' );
this.transaction.commit();
this.transaction = null;
},
transitionAfterSave: function() {
console.log( 'trans' );
if ( this.get('content.id' ) ) {
console.log(this.get( 'content' ));
this.transitionToRoute( 'app', this.get( 'content' ) );
}
}.observes( 'content.id' ),
cancel: function() {
console.log( 'cancel' );
this.stopEditing();
this.transitionToRoute( 'apps' );
}
});
这是我的路线
WEM.Router.map(function(){
this.resource( 'apps', { path: '/' }, function(){
this.resource( 'create_app', { path: 'apps/new' } );
this.resource( 'app', { path: 'app/:app_id'}, function(){
this.resource( 'settings', { path: 'settings' } );
this.resource( 'error', { path: 'error/:error_id' } );
});
});
});