Ionik 2 burchakli NavController, oxirgi ikkinchi sahifaga pop

Quyidagi navigatsiya ishim bor:

Home -> navCtrl.push(SearchPage) -> navCtrl.push(ResultPage)

yoki

Home -> navCtrl.push(SearchPage) -> navCtrl.push(ResultPage) -> navCtrl.push(DetailPage)

SearchPage-ga qaytib borishni xohlayman. Birinchi holda, muammo yo'q, men foydalanishim mumkin

this.navCtrl.pop()

Ammo, ikkinchi holda, men foydalanishga harakat qilaman

this.navCtrl.popTo(SearchPage)

va bu kutilganidek ishlamaydi. Ion suyakka bir sahifani qayta ko'rib chiqadi. PopTo() bilan muammo borligini bilaman ( https://github.com/driftyco/ionic/issues/6513 )

Ushbu muammoni qanday hal qilishim mumkin?

2

8 javoblar

Buni ko'ring! detailPage ichida bo'lganingizda, quyidagilarni bajaring:

this.navCtrl.remove(2,1);//This will remove the 'ResultPage' from stack.
this.navCtrl.pop(); //This will pop the 'DetailPage', and take you to 'SearchPage'
5
qo'shib qo'ydi

Bu yerda shunga o'xshash savolga javob berdim va bu sizning uchun ham taalluqli ko'rinadi. Modullarni band qilib qo'yganimdan boshlab, popTo() faqat NavController.getViews() qatoridan ob'ektni topshirganimda ishlaydi. Buning bilan siz shunday bir narsani sinashingiz mumkin:

let targetView = this._navCtrl.getViews().filter(view=> view.id == 'MyAwesomePage')
targetView.length ? this._navCtrl.popTo(targetView[0]) : this._navCtrl.pop()

Yoki shunga o'xshash yana bir narsa:

let index: number;
let views: any[] = this._navCtrl.getViews()
let found: boolean = views.some((view, i) =>{
  index = i
  return (view.id == 'MyAwesomePage')
})
found ? this._navCtrl.popTo(views[index]) : this._navCtrl.pop()

Buyurtmani o'zgartirishni xohlasangiz, siz (), revers (), filter() yoki views.reverse() funktsiyalarini olishingiz mumkin. Bu Ionic 3 va ES5 ning Array.some ()

1
qo'shib qo'ydi
this.navController.push(SearchPage).then(() => {
  const index = this.viewCtrl.index;
  this.navController.remove(index, 1); //this will remove page3 and page2
});

Ushbu kodni komponentingizga qo'shing.

1
qo'shib qo'ydi
 this.nav.push(AnotherPage)
 .then(() => {
    const index = this.viewCtrl.index;
    this.nav.remove(index);
 });
1
qo'shib qo'ydi

OK, hal qildi. Hech bo'lmaganda, hozirgacha ishlaydi

this.navCtrl
        .push(SearchPage)
        .then(() => {

            const index = this.viewCtrl.index;

            for(let i = index; i > 0; i--){
                this.navCtrl.remove(i);
            }

        });
1
qo'shib qo'ydi

Buni siz navigatsiya tekshiruvi stackini insertPage usulidan foydalanib o'zgartirishingiz mumkin.

 this.nav.insertPages(0, [{page: your_home_page}, {page: SearchPage}]);
 this.nav.pop();

Bu erda 0 sizning sahifani qo'shishni istagan joyga ishora qiladi. Yuqoridagi kodda 0 sizning bosh sahifangiz bo'ladi va 1 sizning qidiruv sahifangiz bo'ladi. Ushbu buyrug'ni SearchPage-ga pop-navigatsiya qilish uchun DetailPage-dan foydalaning.

For more information check http://ionicframework.com/docs/v2/api/navigation/NavController/

0
qo'shib qo'ydi
this.navCtrl.remove (0) qo'shishni harakat qilib ko'ring; kodning boshqa satrlarini qo'shishdan oldin. Bu sahifani 0-postda to'plamdan olib tashlashga yordam beradi
qo'shib qo'ydi muallif AishApp, manba
savolingizda Nav.Push haqida gapirgansiz. Nav, Nav yoki NavController. NavControllerni ikkalasini itarish va ochish uchun ishlatasizmi?
qo'shib qo'ydi muallif AishApp, manba
Men uchun u execPages-dan foydalanib ishlaydi. linkdan bu.nav.removeView (this.viewCtrl) dan foydalaning; this.nav.remove (indeks) o'rniga; Umid qilamanki
qo'shib qo'ydi muallif AishApp, manba
Rahmat, lekin hech qanday ta'siri yo'q. U bir sahifani orqaga qaytaradi. getSearchPage() {this.navCtrl.insertPages (0, [{page: HomePage}, {page: SearchPage}]); bu.navCtrl.pop (); }
qo'shib qo'ydi muallif hydrococcus, manba
Hech qanday ta'siri yo'q. Yo'qotgandirman.
qo'shib qo'ydi muallif hydrococcus, manba
Ha, bu NavController. Contructor public navCtrl: NavController da belgilangan. Yuqorida men yuqoridagi xabarni tuzatishim kerak
qo'shib qo'ydi muallif hydrococcus, manba
boshqa echim topdim Bu yerda . Bu ishlaydi, lekin agar push (SearchPage) dan keyin "tugma" tugmasini bosgan bo'lsam, ResultPage hali ham suyak ichida.
qo'shib qo'ydi muallif hydrococcus, manba

Men ham xuddi shu muammoga duch kelib, echimni topdim, qabul qilingan javobga o'xshaydi, lekin loopsiz va biroz tafsilotlarsiz, shuning uchun kimdir buni tushunishga yordam beradi deb umid qilaman.

Shunday qilib, oqim shunday:

Home -> navCtrl.push(SearchPage) -> navCtrl.push(ResultPage) -> navCtrl.push(DetailPage)

Va bu erda tegishli indeks:

Home: 0
SearchPage: 1
ResultPage: 2 
DetailPage: 3

DetailPage-dan SearchPage-ga qaytib borishni istasangiz, DetailPage-ni bosganingizda ResultPage-ni qatlamdan o'chirishni xohlaysiz.

DetailPage-ni bosganingizda, ushbu kodni ResultPage-da sinab ko'ring:

// First get the index of ResultPage, it should return 2.
let resultIndex = this.navCtrl.last().index; 

// Push DetailPage.
this.navCtrl.push(DetailPage).then(() => {
 //Once it's pushed, this block is called and now we can remove the ResultPage from the stack.
  this.navCtrl.remove(resultIndex, 1); 
 //second parameter is optional and defaults to 1, if you want to remove more pages from stack start with the bottom most index you want to remove and pass number of pages you want to remove starting from the given index. 

});

Umid qilamanki, bu biror kishiga yordam beradi.

0
qo'shib qo'ydi

Mening ishimda bu ish yoqdi

import { NavController, NavParams } from 'ionic-angular';

export class MyComponent {
    ...
    constructor(private navParams:NavParams, private navCtrl:NavController){
        //If I get the paramater, I know I have to "skip" last view
        let condition = this.navParams.get("condition");
        if (condition){
            this.navCtrl.removeView(this.navCtrl.last());
        }
    }
    ...
}

Shunday qilib, siz yumshoq/qattiq tugmani yoki faqat pop() bilan qo'lda qaytsangiz, oldingi versiya o'tkazib yuboriladi.

0
qo'shib qo'ydi
Angular Uzbekistan
Angular Uzbekistan
107 ishtirokchilar

Guruh Angular bo'yicha muloqot qilish uchun ochilgan Sizni qiziqtirsa: @nodejs_uz @react_uz @angular_uz @yiiframework_uz @js_uzb @typescript_uzb @vuejs_uz @ngTashkent @laravel_uz @uzdevgroup Ish o'rinlari @UzDev_jobs

ngTashkent
ngTashkent
77 ishtirokchilar

Правила просты: 1. Не хамить 2. Не хейтить 3. Реакт не нужен Ссылки: https://t.me/angular_ru - старший брат https://t.me/angular_uz - ангулар на узбекском @js_uzb @vuejs_uz @react_uz @nodejs_uz @yiiframework_uz @uzdevgroup @UzDev_Jobs @tasdev_talks