React-Native 循环点击事件

简单做个小例子,如下:

constructor(props) {
        super(props);
        this.state = {
            Data: [
                {key:1,value:'工商银行'},
                {key:2,value:'建设银行'}
                ],
            bankValue: ''   //选中数据
        }
render() {
        return (
            
                
                    {
                        this.state.Data.map((item,index)=> {
                            return(
                                
                                   this._click(item,index)}>{item.value}
                                

                            )}
                        )
                    }
                
                我选择的银行:{this.state.bankValue}
            
        )
    }

_click(item,index) {
        alert(index)
        this.setState({
            bankValue: item.value
        })
    }

React-Native 循环点击事件_第1张图片

你可能感兴趣的:(ReactNative)