我试图通过删除该项目来解决问题,但它似乎不起作用。 我想知道,我忘了将某些内容传递到命令中吗?
希望屏幕和我的代码能使我的解释更简短
这是我的代码
员工创建.js
import React,{Component} from 'react';
import { Picker, Text } from 'react-native';
import { connect } from 'react-redux';
import { employeeUpdate } from '../actions';
import {Card,CardSection,Input,Button} from './common';
class EmployeeCreate extends Component {
render () {
return (
<Card>
<CardSection>
<Input
label="Name"
placeholder="jane"
/>
</CardSection>
<CardSection>
<Input
label="Phone"
placeholder="08122030930"
/>
</CardSection>
<CardSection style={{flexDirection:'column'}}>
<Text style={styles.pickerTextStyle}>Select your shift</Text>
<Picker
selectedValue={this.props.shift}
onValueChange={day => this.props.employeeUpdate ({prop:'shift' , value: day})}
>
<Picker.item label="Monday" value="Monday" />
<Picker.item label="Tuesday" value="Tuesday" />
<Picker.item label="Wednesday" value="Wednesday" />
<Picker.item label="Thursday" value="Thursday" />
<Picker.item label="Friday" value="Friday" />
<Picker.item label="Saturday" value="Saturday" />
<Picker.item label="Sunday" value="Sunday" />
</Picker>
</CardSection>
<CardSection>
<Button>
create
</Button>
</CardSection>
</Card>
);
}
}
const styles = {
pickerTextStyle: {
fontSize: 18,
paddingLeft: 20
}
};
const mapStateToProps =(state) => {
const { name,phone,shift } = state.employeeForm ;
return {name,phone,shift};
};
export default connect (mapStateToProps,{employeeUpdate}) (EmployeeCreate)
;
这里还附上了它的图片在此处输入图像描述
如果您要调用的函数是employeeUpdate
是从 ./actions
导入的函数,则应删除this.props.
否则,可能需要在 EmployeeCreate
的父类中定义该函数。