weui / react-weui

weui for react
https://weui.github.io/react-weui/docs/
2.85k stars 492 forks source link

Citypicker选中和展示不一致 #235

Open undead25 opened 7 years ago

undead25 commented 7 years ago

Do you want to request a feature or report a bug (建议还是bug) ?

What is the current behavior? (现有状况)

What is the expected behavior? (应有状况)

Which versions of React-weui, weui, and which OS and device are affected by this issue? (React-weui版本 weui版本 机型和系统)

重现

  1. 弹出城市选择器
  2. 选中:河北 -> 唐山 -> ...
  3. 选中:天津 -> ... -> ...
  4. 确定按钮

[数据不一致。]

代码对应位置

updateGroup(item, i, groupIndex, selected, picker) {
  const { data, dataMap } = this.props;
  //validate if item exists

  const { groups, newselected } = this.parseData(data, dataMap.items, selected);

  let text = '';
  try {
    groups.forEach((group, _i) => {
      text += `${group['items'][selected[_i]][this.props.dataMap.id]} `;
    });
  } catch (err) {
    //wait
    text = this.state.text;
  }

  //console.log(groups)
  this.setState({
    groups,
    text,
    selected: newselected
  });

  //update picker
  picker.setState({
    selected: newselected
  });
}

建议 将value的赋值放在setState的回调里面