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

Picker组件关于异步设定 range与value问题 #2797

Closed
QsonXu opened this issue Apr 17, 2019 · 4 comments
Closed

Picker组件关于异步设定 range与value问题 #2797

QsonXu opened this issue Apr 17, 2019 · 4 comments
Assignees

Comments

@QsonXu
Copy link

QsonXu commented Apr 17, 2019

问题描述
目前使用的taro版本是 1.2.26,以下是代码清单。

复现步骤
[复现问题的步骤]

  1. 初始化picker,同时range 与 value(位置: 3) 初始化
    2.“ 点击更新Picker(a->aa)” 这个时候 range 与 value(位置: 1)发生变更,
    error: 这个时候的Picker是停留在位置3。
// 这里可以贴代码

import Taro, { Component } from '@tarojs/taro';

import { View, Text, Picker } from '@tarojs/components'
 
import './test.scss';

class Test extends Component {

  constructor(props) {
    super(props);
    this.validType = '';
    let SID = 2;
    let selector = [
      {value:'a', key:1},
      {value:'b', key:2},
      {value:'c', key:3},
      {value:'d', key:4},
    ];

    this.state = {
      selector:selector,
      sid: SID,
      selectorChecked:selector[SID].value
    };
  }
 
  onChange(e){
    console.log(e.detail.value);
    this.setState({
      selectorChecked: this.state.selector[e.detail.value].value
    });
  }

  handleClick(){
    let selector = [
      {value:'aa', key:5},
      {value:'bb', key:6},
      {value:'cc', key:7},
      {value:'dd', key:8},
    ];
    let SID = 1;

    this.setState({
      selector:selector,
      sid: SID,
      selectorChecked:selector[SID].value
    });
  }
 
  render() {

    return (
      <View className='test'>
          <View className='page-section'>
            <Text onClick={this.handleClick.bind(this)}>点击更新Picker(a->aa)</Text>
            <View>
              <Picker mode='selector' range={this.state.selector} value={this.state.sid} rangeKey='value' onChange={this.onChange.bind(this)}>
                <View className='picker'>
                  当前选择:{this.state.selectorChecked}
                </View>
              </Picker>
            </View>
           </View>
      </View>
    );
  }
}

export default Test;

期望行为
像这种情况如何处理?能不能直接把Picker销毁,再重新重新实例化,变成新值range与value.

系统信息

Taro v1.2 及以上版本已添加 taro info 命令,方便大家查看系统及依赖信息,运行该命令后将结果贴下面即可。

  • 操作系统: [e.g. Windows 10]
  • Taro 版本 [e.g. v.1.2.26]
  • Node.js 版本 [e.g. v10.15.3]
  • 报错平台 [h5]

补充信息
主要是原因是更新range 与 value的时候,并不触发Picker的 updateHeight()

@taro-bot
Copy link

taro-bot bot commented Apr 17, 2019

欢迎提交 Issue~

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

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

Good luck and happy coding~

@taro-bot
Copy link

taro-bot bot commented Apr 17, 2019

CC @jinjinjin0731

@jinjinjin0731
Copy link
Contributor

jinjinjin0731 commented Apr 17, 2019

已修复,待下个版本。 如果紧急需要, 你可以在 node_modules 的 @tarojs / components 中找到该组件,按照提交修改一下即可

@QsonXu
Copy link
Author

QsonXu commented Apr 17, 2019

感谢感谢

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

3 participants