[英]Redirecting to error state from action in Ember.js controller
While writing my first app in Ember.js II ran into a problem where I wanted to execute an action through calling some API with jQuery. 在Ember.js中编写我的第一个应用程序时,我遇到了一个问题,我想通过使用jQuery调用一些API来执行操作。 When this call fails, I want the page to be redirected to the error state. 当此调用失败时,我希望页面被重定向到错误状态。
I've been trying to get my head around this one. 我一直在努力解决这个问题。 I created an action like this: 我创建了一个这样的动作:
Contributionkeeper.RepositoriesController = Ember.Controller.extend({
actions: {
delete: function(repo) {
Ember.$.ajax({
url: '...',
success: function(data) { },
error: function() {
//TODO: Raise error
});
}
}
});
I want the application to navigate to an error substate. 我希望应用程序导航到错误子状态。 How can I fix this? 我怎样才能解决这个问题?
It will depend on what whether you want to enter a specific error state (for the general application, one specific to Repositories, etc). 这取决于您是否要输入特定的错误状态(对于一般应用程序,特定于存储库等)。
The general idea is to transition to the state you wish as follows: 一般的想法是按照以下方式过渡到您希望的状态:
Contributionkeeper.RepositoriesController = Ember.Controller.extend({
actions: {
delete: function(repo) {
Ember.$.ajax({
url: '...',
success: function(data) { },
error: function() {
return this.transitionTo('yourErrorLocation');
});
}
}
});
See the documentation regarding Loading and Error substates for more details. 有关更多详细信息,请参见有关“ 加载和错误”子状态的文档。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.