Nativescript: Как создать поведение, подобное Angular routerlinklink - PullRequest
0 голосов
/ 03 октября 2019

Прямо сейчас у меня есть этот компонент, это компонент функции поиска:

App Search Result

Вот код для него:

<StackLayout>
    <StackLayout class="form">
        <StackLayout class="input-field">
            <TextField hint="Tournament Name" [(ngModel)]="query"></TextField>
        </StackLayout>
        <Button text="Search" (tap)="onSubmit()"></Button>
    </StackLayout>
    <Scrollview height="80%">
        <StackLayout>
            <GridLayout *ngFor="let result of results" (tap)="onTap(result.tournament_id)" columns="*, *" rows="auto, auto, auto, auto, auto, auto" borderWidth="1px">
                <Label  [text]="result.name" row="0" col="0" colspan="2" ></Label>
                <Label  [text]="result.organization" row="1" col="0" colspan="2" ></Label>
                <Label  [text]="result.date" row="2" col="0" ></Label>
                <Label  [text]="result.time" row="2" col="1" ></Label>
                <Label  [text]="result.game" row="3" col="0" colspan="2" ></Label>
                <Label  [text]="result.style" row="4" col="0" colspan="2" ></Label>
                <Label  [text]="result.location" row="5" col="0" colspan="2" textWrap="true"></Label>
            </GridLayout>
        </StackLayout>
    </Scrollview>
</StackLayout>

При нажатии на одно из описаний турнира должна появиться страница профиля турнира, например:

Tournament Page on Web

Прямо сейчас у меня есть onTap, привязанный квот такие поля:

  onTap(id){
    console.log("tapped", id);
    this.routerExtensions.navigate(["/tournaments","profile", id]).then(nav => {
              console.log(nav); // true if navigation is successful
              }, err => {
              console.log(err) // when there's an error
              });

  }

Когда я нажимаю на поле, оно печатает:

tapped {id} //first click
true
tapped {id} //subsequent clicks
null

Как создать поведение типа Angular Web routerlink в приложении родного сценария, где нажатие наобъект вызывает другой компонент?

1 Ответ

1 голос
/ 03 октября 2019

Вы должны использовать nsRouterLink, как описано в Угловая навигация Документы.

...