本文介绍了TabView本机脚本中的动态选项卡的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
是否可以在本机脚本中为Tabview动态创建标签?
Is it possible to create tabs dynamically for a tabview in nativescript?
以下示例在nativescript文档中
The following example is in the documentation of nativescript
<TabView selectedIndex="0" (selectedIndexChange)="onIndexChanged($event)" sdkExampleTitle sdkToggleNavButton>
<StackLayout *tabItem="{title: 'NativeScript'}">
<Label text="NativeScript" class="m-15 h2 text-left" color="blue"></Label>
<ScrollView>
<Label [text]="content" textWrap="true" class="m-15"></Label>
</ScrollView>
</StackLayout>
<StackLayout *tabItem="{title: 'Icon'}">
<Image class="m-t-30 m-b-15" src="res://icon" width="80" height="80"></Image>
<Label text="NativeScript" textWrap="true" class="h2 m-x-auto" color="blue"></Label>
</StackLayout>
</TabView>
并且它不允许我使用ng,因为StackLayout元素已经具有以*开头的指令.
and it does not allow me to use the ng for since the StackLayout element already has a directive that starts with *
推荐答案
可以!使用*ngFor
<TabView>
<ng-container *ngFor="let tab of tabList">
<StackLayout *tabItem="tab">
.....
</StackLayout>
</ng-container>
</TabView>
这篇关于TabView本机脚本中的动态选项卡的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!