신입생 React Native
입니다.React Native 버튼을 누를 때마다 TextInput 구성 요소가 차례로 추가됩니다.
두 개의 버튼을 사용하여 TextInput
구성 요소를보기에 추가하고 있습니다. Add
버튼을 누르면 TextInput
구성 요소가 뷰에 들어가고 Add Again
버튼을 누르면 이전에 다른 TextInput
구성 요소가 푸시됩니다.
그러나 다시 Add
버튼을 누르면 TextInput
구성 요소가 첫 번째 구성 요소 아래에 푸시됩니다. 그러나 나는 그것을 마지막 것 아래에 밀어 넣고 싶다.
처럼 : Add |Add | Add again.
하지만 등등 Add | Add Again | Add
및 필요합니다.
이 작업을 수행하기 위해 수행 할 수있는 작업은 무엇입니까? 나는 this을 따라갔습니다.
'use strict';
import React, {Component} from 'react';
import {
AppRegistry,
StyleSheet,
Text,
View,
TouchableHighlight,
TextInput,
} from 'react-native';
let index = 0
class Test extends Component{
constructor(){
super();
this.state = {
arr: []
};
}
insertSomeThing(){
this.state.arr.push(index++)
this.setState({ arr: this.state.arr })
}
render() {
let arr = this.state.arr.map((r, i) => {
return (
<View key={ i } style={styles.insertStyle}>
<TextInput placeholder = 'abc' />
</View>
);
})
let arrAnother = this.state.arr.map((r, i) => {
return (
<View key={ i } style={styles.insertStyle}>
<TextInput placeholder = 'def' />
</View>
);
})
return (
<View style={styles.container}>
<View>
<TouchableHighlight
onPress={ this.insertSomeThing.bind(this) }
style={styles.button}>
<Text>Add</Text>
</TouchableHighlight>
</View>
<View>
<TouchableHighlight
onPress={ this.insertSomeThing.bind(this) }
style={styles.button}>
<Text>Add Again</Text>
</TouchableHighlight>
</View>
{ arr }
{arrAnother}
</View>
);
}
}
var styles = StyleSheet.create({
container: {
flex: 1,
marginTop: 60,
},
insertStyle: {
height:40,
alignItems: 'center',
justifyContent: 'center',
borderBottomColor: '#ededed',
borderBottomWidth: 1
},
button: {
alignItems: 'center',
justifyContent: 'center',
height:55,
backgroundColor: '#ededed',
marginBottom:10
}
});
AppRegistry.registerComponent('Test',() => Test);
입력 텍스트를 별도로 검색 할 수 있도록 onChangeText 및 value를 사용하는 방법은 무엇입니까? –
내 편집을 확인하십시오 – leo7r
마지막 하나, 매핑 기능에서 변경해야하는 부분 또는 구성 요소를 다음과 같이 푸시하고 싶은 부분 : TextInput | 텍스트 | TextInput 등등? –