0
반응 프로젝트에 네이티브 프로젝트가 있습니다. 목록보기와 모달, 목록보기 생성자가 필요하며 모달 생성자가 필요합니다. 두 생성자를 사용하려고하면 오류가 발생합니다. 이 사건을 해결할 수 있을까요? 도와주세요 !!반응 네이티브에서 두 생성자를 사용합니다.
import React, { Component } from 'react';
import {
StyleSheet,
ToolbarAndroid
,AppRegistry,
View,
Text,
TouchableHighlight,
Modal,
TextInput,
ListView,ActionButton,
Image,
Alert
} from 'react-native';
var DialogAndroid = require('react-native-dialogs');
export default class HygexListView extends Component {
constructor() {
super(...arguments);
this.state = {
visible: false
};
}
constructor(props){
super(props);
var ds = new ListView.DataSource({
rowHasChanged: (r1, r2) => r1 != r2
});
this.state = {
ds:[{CustomerName: "Customer Name", CustomerPhone: "+564659878964"},{CustomerName: "Customer Name", CustomerPhone: "+564659878964"},{CustomerName: "Customer Name", CustomerPhone: "+564659878964"},{CustomerName: "Customer Name", CustomerPhone: "+564659878964"},{CustomerName: "Customer Name", CustomerPhone: "+564659878964"},{CustomerName: "Customer Name", CustomerPhone: "+564659878964"},{CustomerName: "Customer Name", CustomerPhone: "+564659878964"},{CustomerName: "Customer Name", CustomerPhone: "+564659878964"},{CustomerName: "Customer Name", CustomerPhone: "+564659878964"}],
dataSource:ds,
}
}
componentDidMount(){
this.setState({
dataSource:this.state.dataSource.cloneWithRows(this.state.ds),
})
}
pressRow(rowData){
var newDs = [];
newDs = this.state.ds;
newDs[0].Selection = newDs[0] == "CustomerName" ? "CustomerPhone" : "";
this.setState({
dataSource: this.state.dataSource.cloneWithRows(newDs)
})
showModal =() => {
this.setState({
visible: true
});
};
hideModal =() => {
this.setState({
visible: false
});
};
}
renderRow(rowData){
return (
<TouchableHighlight
onPress={()=> this.showModal()}
underlayColor = '#ddd'>
<View style ={styles.row}>
<Text style={{fontSize:19}}>{rowData.CustomerName} {"\n"} {rowData.CustomerPhone} </Text>
<View style={{flex:1}}>
<Text style={styles.selectionText}>{rowData[rowData.Selection]}</Text>
</View>
</View>
</TouchableHighlight>
)
}
render() {
return (
<View style={styles.container}>
<View style={styles.toolbar}>
<TouchableHighlight >
<Image style={styles.imagestyle}
source={require('./ic_search.png')}/>
</TouchableHighlight>
<Text style={styles.toolbarTitle}>CUSTOMERS</Text>
<TouchableHighlight onPress={() => this.moveToAddNewCustomer()}>
<Image style={styles.imagestyle}
source={require('./ic_action_name.png')} />
</TouchableHighlight>
</View>
<ListView
dataSource = {this.state.dataSource}
renderRow = {this.renderRow.bind(this)}>
</ListView>
<View style={styles.x}>
<TouchableHighlight style={styles.action1}>
<Text style={styles.actionText}>CUSTOMERS</Text>
</TouchableHighlight>
<TouchableHighlight style={styles.action1}
onPress={() => this.moveToOrderEntry()}>
<Text style={styles.actionText}>Order Entry</Text>
</TouchableHighlight>
<TouchableHighlight style={styles.action}
onPress={() => this.moveToMyOredre()}>
<Text style={styles.actionTex1}>My Order</Text>
</TouchableHighlight>
</View>
<Modal
visible={this.state.visible}
>
<View style={styles.modalContainer}>
<View style={styles.toolbar}>
<View>
<Text style={styles.toolbarTitle}>X</Text>
</View>
<Text style={styles.toolbarTitle}>Details</Text>
</View>
<View style={styles.ButtonflexDirection}>
<Text >CUSTOMER Name</Text>
</View>
<View style={styles.ButtonflexDirection}>
<Text >Address</Text>
</View>
<View style={styles.ButtonflexDirection}>
<Text >Phone Number</Text>
</View>
<View style={styles.ButtonflexDirection}>
<Text >Interested Product</Text>
</View>
<View style={styles.ButtonflexDirection}>
<Text >Discount</Text>
</View>
<View >
<TouchableHighlight style={styles.button}
onPress={() => this.moveToHygexListView()}>
<Text style={styles.buttonText}> ADD ORDER</Text>
</TouchableHighlight>
</View>
</View>
</Modal>
</View>
)
}
moveToMyOredre() {
this.props.navigator.push({
id: 'MyOrder'
})
}
moveToOrderEntry() {
this.props.navigator.push({
id: 'OrderEntry'
})
}
moveToAddNewCustomer() {
this.props.navigator.push({
id: 'AddNewCustomer'
})
}
}
이 ES6에서 그런 종류의 다형성이없고, 인스턴스는 항상 당신이 어떤을 작성하지 않은 경우에도, 인수에'props' 값을받을 것이다 매개 변수는 함수 선언에 있으므로 두 개의 생성자를 사용할 수 없습니다. 보기와 모달에 생성자가 필요하다고 말합니다. 그게 정확히 무슨 뜻입니까? – martinarroyo
이 코드는 내 코드를 검사 할 때 코드를 실행할 때 "duplicate use constructor"이라는 오류가 발생했습니다! 그것을 해결하는 방법? –
두 개의 생성자를 사용할 수 없습니다. 양쪽 모두의 로직을 하나로 통합하면 제대로 작동합니다. – martinarroyo