私は約2時間を費やしました。本当に助けが必要です。私は私の配列からランダムな色を取得し、その1色にbackgroundColorを設定したいと思います。コードをそこにコピーしました。 https://jsfiddle.net/1x0k2ot4/配列から無作為にbackgroundColorを設定してください
ありがとうございました。
constructor(props) {
super(props);
const ds = new ListView.DataSource({rowHasChanged: (r1, r2) => r1 !== r2});
this.state = {
inputValue: '',
backgroundColor: '',
dataSource: ds.cloneWithRows([]),
};
this._handleTextChange = this._handleTextChange.bind(this);
this._handleDeleteButtonPress = this._handleDeleteButtonPress.bind(this);
this._setColor = this._setColor.bind(this);
}
_setColor() {
const backgroundColor = backgroundcolors[Math.floor(Math.random()*backgroundcolors.length)];
this.setState({
backgroundColor: backgroundColor
})
}<View style={{ backgroundColor: this.state.backgroundColor, alignItems: 'center', height: 80, padding: 8, borderWidth: 1.5, borderColor: '#e0e0e0', flex: 1, flexDirection: 'row', marginBottom: 5,}}>
<Text style={styles.todoText}>{rowData}</Text>
<View>
<TouchableHighlight onPress={handleDelete} style={styles.crossCloseButton}>
<View>
<Image style={styles.imgClose} source={{uri: 'http://playground.davidfutera.cz/close.png'}}/>
</View>
</TouchableHighlight>
</View>
</View>
あなたが今見ている動作、予想される動作(負荷時などのときのランダムな色)、これまでに試したことを含みます。 –