以下代码是初期写的代码,后来对代码进行优化,解决了初期的bug。完整的选择城市三级联动组件可以参考我的github项目中的代码,这是后期调试成功上传上去的React选择城市三级联动组件
<SelectArea allAreaInfo={allAreaInfo} province={province}
city={city} district={district}
cancel={this.closeModal} confirm={this.SelectAddress} />
import React, { Component, PropTypes } from 'react';
import { connect } from 'react-redux';
import { Link } from 'react-router';
import rest from '../../lib/rest';
const HEIGHT = 36;
export class Picker extends Component {
constructor(props) {
super(props);
this.state = {
selectedIndex: this.props.index
};
this.onScroll = this.onScroll.bind(this);
this.resetPosition = this.resetPosition.bind(this);
}
componentDidMount() {
this.refs.scroller.scrollTop = this.state.selectedIndex * HEIGHT;
this.refs.scroller.addEventListener('touchstart', this.touchStart, false);
this.refs.scroller.addEventListener('touchend', this.touchEnd, false<