我有一个Ember列表和一个编辑表单.每次更改列表的选定项目时,编辑表单将丢弃所有更改并加载新模型.
我的问题是没有办法放弃更改,因为停用事件不会触发.
例如,从url/favs/123/edit去url/favs/456/edit激活(和退出)事件不会触发.因此无法正确丢弃任何更改.
这是我所指的代码的一部分:
App.Router.map(function() {
this.resource('favs', { path: '/favs' }, function() {
this.route('new');
this.route('edit', { path: ':fav_id/edit' })
});
});
[...]
App.FavsEditRoute = Ember.Route.extend({
deactivate: function() {
var model = this.get('currentModel');
if(model && model.get('isDirty')) {
model.get('transaction').rollback();
}
},
model: function(params) {
return App.Fav.find(params.fav_id);
},
});
Run Code Online (Sandbox Code Playgroud) App.Router.map(function() {
this.resource('documents', { path: '/documents' }, function() {
this.route('edit', { path: ':document_id/edit' });
});
this.resource('documentsFiltered', { path: '/documents/:type_id' }, function() {
this.route('edit', { path: ':document_id/edit' });
this.route('new');
});
});
Run Code Online (Sandbox Code Playgroud)
这个控制器带有一个子视图事件,基本上转换为过滤后的文档
App.DocumentsController = Ember.ArrayController.extend({
subview: function(context) {
Ember.run.next(this, function() {
//window.location.hash = '#/documents/'+context.id;
return this.transitionTo('documentsFiltered', context);
});
},
});
Run Code Online (Sandbox Code Playgroud)
我的问题是,当页面哈希值更改时,此代码可以正常工作。
但是当我运行上面的代码而不使用 location.hash 位并且使用 Ember 本机时,transitionTo我得到了一个神秘的信息
未捕获的类型错误:对象 [object Object] 没有方法“切片”
有什么线索吗?
谢谢
更新:
App.DocumentsFilteredRoute = Ember.Route.extend({
model: function(params) {
return App.Document.find({type_id: params.type_id});
},
});
{{#collection contentBinding="documents" tagName="ul" class="content-nav"}}
<li …Run Code Online (Sandbox Code Playgroud)