我无法从Screen(App.js)中传递数组(或变量)以填充组件中的另一个数组。
app.js:
<SelectBoxPopUp values={brands}>
</SelectBoxPopUp>
component.js:
import React from 'react';
import {StyleSheet, View, Text, TouchableOpacity} from 'react-native';
let array1 = this.props.values,
array2 = this.props.values,
radioProps = [];
for ( var i = 0; i < array1.length; i++ ) {
radioProps.push({
label: array1[i],
value: array2[i]
});
}
export default class SelectBoxPopup extends React.Component {
constructor(props) {
super(props);
this.state = {value: 0};
}
render() {
return (
<View>
<Text>...</Text>
</View>
)
}
}
答案 0 :(得分:0)
您正在做的事情在SelectBoxPopup组件中是错误的。您应该执行以下操作
export default class SelectBoxPopup extends React.Component {
constructor(props) {
super(props);
this.state = {value: 0, radioProps: []};
}
componentDidMount(){
let array1 = this.props.values,
array2 = this.props.values,
radioProps = [];
for ( var i = 0; i < array1.length; i++ ) {
radioProps.push({
label: array1[i],
value: array2[i]
});
}
this.setState({
radioProps
});
}
render() {
return (
<View>
<Text>...</Text>
</View>
)
}
}