Sencha Touch Ext.navigation.View pop to root

2022-01-10 00:00:00 navigation javascript sencha-touch-2

我有一个 Ext.navigation.View,我在其中推送了一些视图.某些用户交互要求我直接返回导航视图的顶层——相当于 iOS 中 UINavigationController 上的 popToRootViewControllerAnimated:.

I have an Ext.navigation.View in which I have pushed a few views. Certain user interactions require that I go directly back to the top level of the navigation view -- the equivalent of popToRootViewControllerAnimated: on a UINavigationController in iOS.

我尝试过各种方法,例如:

I have tried various things like:

while(navigationView.getItems().getCount() > 1)
    navigationView.pop();

while(navigationView.canPop())
    navigationView.pop();

都不行.第一个例子似乎让我陷入了无限循环,这并不奇怪.第二个例子似乎只弹出一个视图.

Neither work. The first example seems to put me into an infinite loop which isn't too surprising. The second example only seems to pop one view off.

所以问题是:在 Sencha Touch(版本 2 开发者预览版)中的 Ext.navigation.View 中弹出到根视图的正确方法是什么?

So the question: What is the proper way to pop to the root view in an Ext.navigation.View in Sencha Touch (version 2 developer preview)?

推荐答案

有许多临时方法可以实现这一目标.

There has been a number of interim methods for achieving this.

我使用的是弹出一个比你曾经拥有的级别数更高的数字,例如

The one I was using was to pop a number higher than the number of levels you would ever have e.g.

navigationView.pop(10);

效果很好,但我对此并不满意,但我看到他们现在引入了一种重置方法.你可以这样称呼它......

and that worked fine, but I was never happy with that, but I see they have now introduced a reset method. Which you can call thus...

navigationView.reset();

在 Sencha 源代码内部(见下文),您可以看到它与 @Mithralas 所说的工作类似,但更容易编写.

Internally within the Sencha source code (see below) you can see that it does a similar job to what @Mithralas said, but just easier to write.

// From the Sencha source code
this.pop(this.getInnerItems().length);

相关文章