0.0.4 • Published 7 years ago

react-native-cascade-select v0.0.4

Weekly downloads
2
License
ISC
Repository
github
Last release
7 years ago

介绍

使用react native scrollView封装,在一组预设数据中进行选择,e.g. 省市区选择。

安装

npm install react-native-cascade-select

API

属性说明类型默认值
data数据源Array<{name:string, sub: Array<{name:string, sub: Array}>}>[]
value值, 格式是value1, value2, value3, 对应数据源的相应级层valueArray0,0,0
visible是否显示面板Booleanfalse
cols列数number3
onChange选中后的回调(val:Array): void
onSelectChange每列数据选择变化后的回调函数(row, column): void
okText确认文本String确定
dismissText取消文本String取消
onOk点击确认时执行的回调(e, value): void
onDismiss点击取消时执行的回调(e): void
title大标题String

效果

image

用法

import { AppRegistry, View, Button } from "react-native";
import React, { Component } from "react";
import Cascade from "react-native-cascade-select";

import city from "./city.json";
const cols = 3;

export default class Index extends Component {
  constructor(props) {
    super(props);
    this.state = {
      visible: false,
      value: [0, 0, 0]
    };
  }

  onChange(val) {
    console.log("array-------->", val);
  }

  onSelectChange(row, column) {
    console.log("第几列-------->", row);
    console.log("第几行-------->", column);
  }

  onOk(e, value) {
    this.setState({ visible: false, value: value });
    console.log("ok-------->", e);
  }

  onDismiss(e) {
    this.setState({ visible: false });
    console.log("dismiss-------->", e);
  }

  render() {
    return (
      <View>
        <Button
          onPress={() => this.setState({ visible: !this.state.visible })}
          title="点我"
        />
        <Cascade
          visible={this.state.visible}
          data={city}
          cols={cols}
          okText="确认"
          dismissText="取消"
          title="选择地区"
          value={this.state.value}
          onChange={val => this.onChange(val)}
          onSelectChange={(row, column) => this.onSelectChange(row, column)}
          onOk={(e, value) => this.onOk(e, value)}
          onDismiss={e => this.onDismiss(e)}
        />
      </View>
    );
  }
}

AppRegistry.registerComponent("Test", () => Index);