Reputation: 2362
I have a list of project and ability to delete each of them, here is my action handler for doing this:
deleteProject: function(params) {
this.store.findRecord('project', params).then(function(project) {
project.deleteRecord();
project.save();
// this.transitionTo('projects');
});
}
What I want to do is to redirect back to route where list of project is displayed. As you can see I've tried to do this using this.transitionTo('projects')
, but it doesn't work because this
does not point to route anymore inside handler.
How to get reference to this route
where this handler is declared in order to make transition to another route?
I'm using Ember v. 1.13
Upvotes: 0
Views: 57
Reputation: 993
Try the following code. Hope it works.
deleteProject: function(params) {
var deleteFlag = false;
this.store.findRecord('project', params).then(function(project) {
project.deleteRecord();
project.save();
deleteFlag = true;
});
if (deleteFlag) {
this.transitionTo('projects');
} else {
....
}
}
Upvotes: 0
Reputation: 2890
The simplest way is a closure:
deleteProject: function(params) {
var self = this;
this.store.findRecord('project', params).then(function(project) {
project.deleteRecord();
project.save();
self.transitionTo('projects');
});
}
Or you could use an arrow function if you're using ember-cli with transpiler:
deleteProject: function(params) {
this.store.findRecord('project', params).then((project) => {
project.deleteRecord();
project.save();
this.transitionTo('projects');
});
}
Upvotes: 1