博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
React Native Picker (逐个添加数据、array循环添加数据)
阅读量:4562 次
发布时间:2019-06-08

本文共 2092 字,大约阅读时间需要 6 分钟。

/**
 Sample React Native App
  *  https://github.com/facebook/react-native
  *  @flow
 */ "use strict" import React, {Component} from 'react' import {
AppRegistry, View, Text, Picker, StyleSheet } from 'react-native' var PickerData = [ '11', '22', '33', '44', '55', '66' ] class HelloWorld extends Component {
constructor(props) {
super(props) this.state={
firstPickerValue: '1', secondPickerValue: PickerData[0], } } updateFirstContent(language) {
this.setState({
firstPickerValue: language, }) } updateSecondContent(language) {
this.setState({
secondPickerValue: language, }) } /* 必须有这个 key , 详细请参考 scrollview 博文 * 也可以
此段代码直接放在Picker组件内, * 这样就是一条一条的添加,不是通过已知数组循环添加 * */ renderPicker(key, i) {
// console.log(key , i) return
} render() {
return (
{this.state.firstPickerValue}
this.updateFirstContent(language)}>
{this.state.secondPickerValue}
this.updateSecondContent(language)}> {PickerData.map((key, i) => this.renderPicker(key, i))}
); } } const styles = StyleSheet.create({
container: {
flex: 1, justifyContent: 'center', alignItems: 'center', backgroundColor: '#F5FCFF' }, text: {
width: 200,
 height: 60, backgroundColor: 'white',
 justifyContent:'center',
 alignItems: 'center',
 borderRadius: 5, }, picker:{
padding: 50 } }) AppRegistry.registerComponent('HelloWorld', () => HelloWorld);

 

转载于:https://www.cnblogs.com/madaha/p/5948589.html

你可能感兴趣的文章
20181227 新的目标
查看>>
androidtab
查看>>
php 事件驱动 消息机制 共享内存
查看>>
剑指offer 二叉树的bfs
查看>>
LeetCode Maximum Subarray
查看>>
让我们再聊聊浏览器资源加载优化
查看>>
underscore demo
查看>>
CSS hack
查看>>
C# Enum Name String Description之间的相互转换
查看>>
PHP wamp server问题
查看>>
Spring Data Redis学习
查看>>
js闭包理解案例-解决for循环为元素注册事件的问题
查看>>
2015.04.23,外语,读书笔记-《Word Power Made Easy》 12 “如何奉承朋友” SESSION 33
查看>>
Spring+SpringMVC+JDBC实现登录
查看>>
生与死之间
查看>>
NEFU 109
查看>>
HDU 5435
查看>>
git从已有分支拉新分支开发
查看>>
滚动条隐藏兼容写法
查看>>
SQL2005查询所有表的大小
查看>>