有人知道为什么react native中的picker标签不起作用吗?

时间:2019-01-12 06:32:48

标签: react-native

我正试图通过从中删除项目来解决问题,但似乎没有用。我想知道,我是否忘记将某些内容传递给命令?

希望屏幕和我的代码可以使我的解释更加简短

这是我的代码

EmployeeCreate.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)

;

这里还附有图片 enter image description here

1 个答案:

答案 0 :(得分:0)

如果您要调用的函数是从employeeUpdate导入的./actions,则应删除this.props. 否则,可能需要在EmployeeCreate的父类中定义函数。