[] // 当前选择的是每一级的每一项,如[1, 0],第一级的第2项,第二级的第一项
}
this.close = this.close.bind(this) // 指定this
this.ok = this.ok.bind(this) // 指定this
}
close () { // 取消按钮事件
this.props.onClose && this.props.onClose()
}
ok () { // 确认按钮事件
this.props.onOk && this.props.onOk(this.state.indexs)
}
onChange (itemIndex, currentIndex) { // itemIndex选中的是第几项,currentIndex第几级发生了变化
const indexArr = []
const { options = [], indexs = [] } = this.state
const re = (arr, index) => { // index为第几层,循环每一级
if (arr && arr.length > 0) {
let childIndex
if (index < currentIndex) { // 当前级小于发生变化的层级, 选中项还是之前的项
childIndex = indexs[index]
关键词:如何封装一个React Native多级联动(代码完成)