javascript 如何返回两个视图状态(类似于 $window.history.go(-2))?
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/22429757/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
How to go back on two view states (something like $window.history.go(-2))?
提问by alexpods
In Ionic I can go back just using:
在 Ionic 我可以回去只使用:
var backView = $ionicViewService.getBackView();
backView && backView.go();
The question is how to go to the view before backView? Something like:
问题是如何在backView之前去view?就像是:
var backBackView = $ionicViewService.getView(-2);
backBackView && backBackView.go();
回答by alexpods
After some experiments I ended with next solution:
经过一些实验,我以下一个解决方案结束:
var backView = $scope.$viewHistory.views[$scope.$viewHistory.backView.backViewId];
$scope.$viewHistory.forcedNav = {
viewId: backView.viewId,
navAction: 'moveBack',
navDirection: 'back'
};
backView && backView.go();
It looks bad for me, but successfully resolves the problem. I hope this will help to someone.
这对我来说看起来很糟糕,但成功解决了问题。我希望这会对某人有所帮助。
Update: Now you could actually call
更新:现在你实际上可以打电话
$ionicHistory.goBack(-2);
which is described in ionic's documentation.
这在ionic 的文档中有所描述。
回答by CyberFerret
I've found the following to be the quickest way to go backwards when deep in a view stack:
我发现以下是在视图堆栈深处返回的最快方法:
$ionicHistory.goBack();
I believe you can call that multiple times in a loop to keep going back in the view history. Of course, you have to inject $ionicHistory in your controller.
我相信您可以在循环中多次调用它以继续返回视图历史记录。当然,您必须在控制器中注入 $ionicHistory。
回答by Deminetix
This is now available in nightlies using $ionicGoBack(amount)
https://github.com/driftyco/ionic/commit/63a0834d63eb87b86238fccde4bf4e77f3540085
现在可以在夜间使用$ionicGoBack(amount)
https://github.com/driftyco/ionic/commit/63a0834d63eb87b86238fccde4bf4e77f3540085