
我正在尝试使用react导航和react-native-dropdown,以便在头文件中有一个下拉列表,以更改下面视图中呈现的内容。
每当我尝试执行处理程序时,当react-native-dropdown尝试再次渲染并使用(this.props.data.map((rows,index) =>等)映射dropdown时,我收到错误消息"undefined is not a function (near‘...this.pros.data.map’)“。
下面是我使用的代码:
import React, {Component} from "react"
import {Dimensions, ScrollView, StyleSheet, width, View, TouchableOpacity} from "react-native"
import {Images} from "../../theme"
import DropdownMenu from 'react-native-dropdown-menu';
import Pdf from 'react-native-pdf';
import { Header } from "react-native/Libraries/NewAppScreen";
import { connect } from 'react-redux';
import { NavigationActions } from 'react-navigation';
import { drop } from "lodash";
class InformationScreen extends Component {
  constructor(props) {
    super(props)
    var informationScreens = props.global.appConfig.information_screens
    var informationScreenTitles = Object.keys(informationScreens)
    state = {
      informationScreens: informationScreens,
      selectedDropdown: informationScreens[0]
    }
}
static navigationOptions = ({ navigation }) => {
  return {
    headerTitle:  <DropdownMenu
    style={{flex: 1}}
    bgColor={'clear'}
    tintColor={'#666666'}
    activityTintColor={'rgba(2, 122, 255, 1.0)'}
    // arrowImg={}
    // checkImage={}
    // optionTextStyle={{color: '#333333'}}
    // titleStyle={{color: '#333333'}}
    // maxHeight={300}
  handler={(selection, row) => navigation.setParams({'headerTitle': navigation.state.params[selection][row]})}
  data={navigation.state.params}
  />
  };
};
    render() {
        return (
          <View style={styles.container}>
          <Pdf
          source={{ uri: "https://someurl.com/dl/sites/default/files/page/2020%20BYU%20Football%20Almanac_3.pdf", cache: true}}
          onLoadComplete={(numberOfPages,filePath)=>{
            console.log(`number of pages: ${numberOfPages}`);
        }}
        style={styles.pdf}
          />
          </View>
        )
    }
}
const styles = StyleSheet.create({
    image: {
        flex: 1,
    },
    container: {
      flex: 1,
      justifyContent: 'flex-start',
      alignItems: 'center',
      marginTop: 25,
  },
  pdf: {
      flex:1,
      width:Dimensions.get('window').width,
      height:Dimensions.get('window').height,
  }
})
function mapStateToProps(state) {
  const global = state.get('global');
  return {  global };
}
export default connect(mapStateToProps)(InformationScreen);发布于 2020-09-17 09:09:16
雷,你说得太对了,我在你发帖前5分钟就知道了。
navigation.state.params是有效的,下拉列表将填充,但是当我尝试使用setParams时,它会将参数的格式更改为JSON对象而不是数组。
这是通过将我的数组放入一个更深的JSON对象来修复的,这样在调用setParams之后,该对象仍然包含数组。然后,我在数据中调用了该对象。
data={navigation.state.params.informationScreens} 非常感谢您的帮助,我将开始更频繁地使用StackOverflow。
https://stackoverflow.com/questions/63929752
复制相似问题