Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

子组件props数据更新在微信小程序中不执行 #4681

Closed
chaonsf opened this issue Oct 24, 2019 · 4 comments
Closed

子组件props数据更新在微信小程序中不执行 #4681

chaonsf opened this issue Oct 24, 2019 · 4 comments

Comments

@chaonsf
Copy link

chaonsf commented Oct 24, 2019

export default class NearByClinic extends Component{
constructor(props){
super(props)
this.state={
hospital_map:props.hospital_map,
visible:false,
HPHP_ID:'',
pointArr:[],
}
}
componentDidMount(){

}
map(point){
    let cli=point.split(',');
    this.setState({
         pointArr:cli,
         visible:true
    })
}
closeMap(){
    this.setState({
        visible:false
    })
}
render(){
    return(
        <View className='at-row'>
             <View className='at-col at-col-10 at-col__offset-1 at-col--wrap'>
                  <Text>{this.props.Text}</Text>
                  {this.state.hospital_map.map((item,index)=>(
                                        <View className="weui-cell weui-cell_access">
                                            {/* <View className='weui-cell__hd'  onClick={this.selectClinic.bind(this,item.HPHP_ID)}>
                                                  <Checkbox checked={this.state.HPHP_ID==item.HPHP_ID?true:false}></Checkbox>
                                            </View> */}
                                             <View className="weui-cell__bd" onClick={()=>this.props.selectClinic(item.HPHP_ID)}>
                                                 <View className='HPHP_NAME'>[{item.HPPN_NAME}]{item.HPHP_NAME}</View>
                                                 <View className="HPHP_ADDR">{item.HPHP_ADDR}</View>
                                             </View>
                                             <View className="weui-cell__ft" onClick={this.map.bind(this,item.BAIDU_POINT)}>查看地图</View>
                                        </View>
                  ))} 
             </View>
             <AtDrawer show={this.state.visible} width='100%'>
                    <Map id='map' longitude={this.state.pointArr[0]} latitude={this.state.pointArr[1]}></Map>
                    <View className='at-row button'>
                        <View className='at-col at-col-10 at-col__offset-1'>
                              <AtButton onClick={this.closeMap.bind(this)} type='primary'>关闭</AtButton>
                        </View>
                    </View>
               </AtDrawer>
        </View>
    )
}

}
NearByClinic.defaultProps={
hospital_map:[]
}
给子组件一个默认值,然后就不渲染了
父组件调用子组件
<NearByClinic Text='可使用诊所:' hospital_map={this.state.hospital_map} selectClinic={(id)=>this.selectClinic(id)}>

@taro-bot
Copy link

taro-bot bot commented Oct 24, 2019

欢迎提交 Issue~

如果你提交的是 bug 报告,请务必遵循 Issue 模板的规范,尽量用简洁的语言描述你的问题,最好能提供一个稳定简单的复现。🙏🙏🙏

如果你的信息提供过于模糊或不足,或者已经其他 issue 已经存在相关内容,你的 issue 有可能会被关闭。

Good luck and happy coding~

@Chen-jj
Copy link
Contributor

Chen-jj commented Oct 24, 2019

@chaonsf 请按 issue 模板提供一切必要信息

@Chen-jj
Copy link
Contributor

Chen-jj commented Oct 24, 2019

@chaonsf 并且整理好代码格式

@taro-bot
Copy link

taro-bot bot commented Oct 24, 2019

Hello~

您的问题所提供的信息不足,我们无法定位到具体的问题。如果有空的话还请拔冗提供更具体的信息,否则这个 issue 将在 15 天后被自动关闭。

如果您在这 15 天中更新更多信息自动关闭的流程会自动取消,如有其他问题也可以发起新的 Issue。

Good luck and happy coding~

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants