react-native - Anyone knows why the label of picker in react native doesn't work?
问题描述
I was trying to solve the problem by removing the item from but it seems didn't work. i wonder, am i forgot to pass something into the command?
hopefully, the screen and my code will make my explanation more briefly
Here is my code
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)
;
here attached also the picture of it enter image description here
解决方案
如果您要调用的函数是employeeUpdate
您从 导入的./actions
,那么您应该删除this.props.
Else,该函数可能需要在 的父类中定义EmployeeCreate
。
推荐阅读
- c++ - 指向具有指针成员的对象的指针数组的析构函数
- python - 模型并行不适用于增加 tensorflow1.12 中的模型大小?
- spring-boot - 运行 Azure DevOps Pipeline 时如何跳过构建测试(Spring Boot Maven 项目)
- python - 如何使用标签将 txt 文件数据集分类为两个数据集?
- networking - 为数据包处理添加延迟 (omnet++)
- google-sso - 带有 Itop 的 Google Workspace SSO
- firebase - 有没有办法仅将 BigQuery 镜像 Firebase Firestore 用于 CREATE 和 DELETE?
- performance - SOLID 原则可以用于高性能代码吗?
- jpa - JPA 多对多映射
- python - 在脚本目录之外时在终端中执行 Python 脚本