1

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

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

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

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

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

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

4

4 回答 4

9

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

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

navigationView.pop(10);

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

navigationView.reset();

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

// From the Sencha source code
this.pop(this.getInnerItems().length);
于 2012-05-16T15:49:47.077 回答
7
popToRoot: function() {
     this.pop(this.getItems().length - 1);
}
于 2012-04-19T07:44:31.923 回答
2

确保使用 NavigationView.reset() 方法。为了清楚起见,如果您的主导航视图是 Main,您将在控制器中执行以下操作:

this.getMain().reset();

于 2013-06-07T19:50:11.737 回答
1

结果证明,解决方案是使用以下内容扩展导航视图:

popToRoot: function(destroy)
{
    var navBar = this.getNavigationBar(),
    stackLn = this.stack.length,
    stackRm;

    //just return if we're at root
    if(stackLn <= 1) return;
    //just return if we're already animating
    if(navBar && navBar.animating) return;

    //splice the stack to get rid of items between top and root
    stackRm = this.stack.splice(1, stackLn-2);
    //remove views that were removed from the stack if required
    if(destroy) {
        stackRm.forEach(function(val, idx, arr) {
            this.remove(val, true);
        });
    }
    //clear out back button stack
    navBar.backButtonStack = [];
    //now we can do a normal pop
    this.pop();
}
于 2012-01-11T16:18:35.237 回答