滑动顶部导航栏动态请求数据问题
来源:7-4 列表实现&数据渲染【封装与复用】
她说影子失了心
2021-03-30
export default class CoursePage extends Component {
// 动态生成Tab栏
_genTabs() {
const tabs = [
{
screen: props => <Course {...this.props} tabLabel={"推荐"} />,
navigationOptions: {
title: '推荐',
}
}
]
// this.state.dataArray 数据源
// brandName Tab栏的名字
this.state.dataArray.map((item, index) => {
tabs[`${index + 1}`] = {
screen: props => <Course {...this.props} tabLabel={item.brandName} />,
navigationOptions: {
title: item.brandName
}
}
})
console.log('tabs=====>', {...this.props.navigation.navigate.length === 0 });
console.log('this.state.dataArray=====>', this.state.dataArray);
return tabs;
}
render() {
console.log('this._genTabs()=====>', this._genTabs());
const MaterialTopTabNavigator = createAppContainer(createMaterialTopTabNavigator(
this._genTabs(),
))
return (
<SafeAreaView style={styles.container}>
<View style={styles.title}>
<Text style={{ fontSize: 20 }}>选择课程</Text>
</View>
<MaterialTopTabNavigator />
</SafeAreaView>
);
}
}
// Course 通过this.state.dataArray[index + 1].brandCode来获取参数
class Course extends React.Component {
//获取课程列表
getClass(index) {
if (index === 0) {
const params = {
channelCode: channelCode,
totalCodes: apprecommend1 + ',' + apprecommend2 + ',' + apprecommend3,
top: 100,
brandCodes: this.state.subject ? this.state.subject : ''
}
getClassRecommend(params).then(value => {
console.log('推荐课', value);
if (value.code === 200) {
this.setState({
classData: value.data
})
}
})
} else {
const params = {
channelCode: channelCode,
brandCode: this.state.dataArray[index + 1].brandCode + ',' + this.state.subject,
}
console.log('app', this.state.dataArray[index + 1].brandCode + ',' + this.state.subject)
getClassList(params).then(value => {
if (value.code === 200) {
this.setState({
classData: value.data
})
}
});
}
}
}
我想请问老师,怎么在动态滑动Tab栏的时候获取我的brandCode来加载数据
写回答
1回答
-
CrazyCodeBoy
2021-04-05
目前还不支持这样的操作。
00
相似问题