【发布时间】:2021-06-27 22:11:05
【问题描述】:
我正在使用 ant design mobile 我在有条件地切换标签时遇到了一些问题。
我有两个选项卡,一个是 topCategorytab,另一个是 subCategory 选项卡,我希望当用户单击其中一个 topCategoryTab 时,立即将 subCategory 选项卡的 activetab 重置为 0。
这是我尝试过的:
<Tabs
tabBarPosition="bottom"
onTabClick={(tab, index) => {
this.getRestaurantItems(
tab.product_category_id,
this.state.currentSubCatId
);
this.findSubCategories(tab.product_category_id);
this.setState({
currentTopCatId: tab.product_category_id,
subCatTabInitialTab: 0,
});
}}
tabs={this.state.tabs}
initialPage={0}
renderTabBar={(props) => <Tabs.DefaultTabBar {...props} page={4} />}
/>
<WhiteSpace />
<Tabs
onTabClick={(tab, index) => {
this.setState({
currentSubCatId: tab.subCatId,
});
this.getRestaurantItems(this.state.currentTopCatId, tab.subCatId);
console.log(
"state sub category id veee top cat id",
this.state.currentTopCatId,
tab.subCatId
);
}}
tabs={this.state.subCategories}
initialPage={0}
goToTab={this.state.subCatTabInitialTab}
renderTabBar={(props) => <Tabs.DefaultTabBar {...props} page={3} />}
>
{this.renderContent}
</Tabs>
在文档中他们说的是:goToTab 调用这个函数来切换 Tab (index: number) => boolean true
但我真的不明白这个 goToTab 函数的用法。
【问题讨论】:
标签: javascript reactjs antd