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

PickerView受控后,渲染问题 #2257

Closed
shenck215 opened this issue Feb 25, 2019 · 9 comments
Closed

PickerView受控后,渲染问题 #2257

shenck215 opened this issue Feb 25, 2019 · 9 comments
Assignees
Labels
question Further information is requested

Comments

@shenck215
Copy link

shenck215 commented Feb 25, 2019

问题描述
PickerView通过控制value值受控,总共三列,在change事件里setState设置value,来选中特定的值。第一列index不变,也就是数组的第一个不变,PickerView不会渲染

复现步骤
image
原本value值是[1,4,4],设置成[1,5,6]这种是不会渲染的,要设置成[0,5,6]才行


**期望行为**
渲染正常

**报错信息**

没有报错

**系统信息**
"dependencies": {
    "@tarojs/async-await": "^1.2.13",
    "@tarojs/components": "1.2.13",
    "@tarojs/mobx": "1.2.13",
    "@tarojs/mobx-h5": "1.2.13",
    "@tarojs/mobx-rn": "1.2.13",
    "@tarojs/rn-runner": "1.2.13",
    "@tarojs/router": "1.2.13",
    "@tarojs/taro": "1.2.13",
    "@tarojs/taro-alipay": "1.2.13",
    "@tarojs/taro-h5": "1.2.13",
    "@tarojs/taro-swan": "1.2.13",
    "@tarojs/taro-tt": "1.2.13",
    "@tarojs/taro-weapp": "1.2.13",
    "mobx": "4.8.0",
    "mobx-persist": "^0.4.1",
    "nerv-devtools": "^1.3.9",
    "nervjs": "^1.3.9",
    "taro-ui": "^2.0.0"
  },
  "devDependencies": {
    "@tarojs/plugin-babel": "1.2.13",
    "@tarojs/plugin-csso": "1.2.13",
    "@tarojs/plugin-sass": "1.2.13",
    "@tarojs/plugin-uglifyjs": "1.2.13",
    "@tarojs/webpack-runner": "1.2.13",
    "@types/react": "16.3.14",
    "@types/webpack-env": "^1.13.6",
    "@typescript-eslint/eslint-plugin": "^1.4.0",
    "@typescript-eslint/parser": "^1.4.0",
    "babel-plugin-transform-class-properties": "^6.24.1",
    "babel-plugin-transform-decorators-legacy": "^1.3.4",
    "babel-plugin-transform-jsx-stylesheet": "^0.6.5",
    "babel-plugin-transform-object-rest-spread": "^6.26.0",
    "babel-preset-env": "^1.6.1",
    "eslint": "^5.14.1",
    "eslint-config-taro": "1.2.13",
    "eslint-plugin-import": "^2.12.0",
    "eslint-plugin-react": "^7.8.2",
    "eslint-plugin-taro": "1.2.13",
    "typescript": "^3.2.2"
  }

**补充信息**
无
@taro-bot
Copy link

taro-bot bot commented Feb 25, 2019

欢迎提交 Issue~

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

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

Good luck and happy coding~

@Chen-jj
Copy link
Contributor

Chen-jj commented Feb 28, 2019

@shenck215 根据文档代码进行测试复现不了,可以提供下你的代码

@taro-bot
Copy link

taro-bot bot commented Feb 28, 2019

CC @jinjinjin0731

@shenck215
Copy link
Author

@Chen-jj
image
初始state是[1,2,2],滚动完触发onChange后,是成功把值设置成了[1,3,3],但是我再滚动一下,就没法渲染成[1,3,3]该有的样子了。场景是我选择错误的日期,就要回滚到一个固定的日期,连续两次选择错误的日期,第二次就没效果了。
image
这个value的受控是不是没法完全受控?就像我这里如果value写死[1,2,2],我去滚动,渲染的样子还是会随着我的滚动而变,不会把值固定成[1,2,2],自己回滚回来

@jinjinjin0731 jinjinjin0731 removed their assignment Mar 1, 2019
@taro-bot
Copy link

taro-bot bot commented Mar 1, 2019

CC @Chen-jj

@jinjinjin0731
Copy link
Contributor

@shenck215 确实有复现,正在排查

@Chen-jj
Copy link
Contributor

Chen-jj commented Mar 1, 2019

@shenck215 是的,小程序原生表单组件不是受控组件,选项改变时其实 PickerView 对应的 data 并没有变化,而 setState 更新时 Taro 会对 setState 的内容和组件 data 做 diff,第二次滚动时发现 state 和 data 都是一样就会放弃 setData。

所以这种需要改变表单 value 为同一恒定值的操作,需要在 onChange 时同步更新 data 值。

onChange = (e) => {
  this.setState({
    value: [
      e.detail.value[0],
      e.detail.value[1],
      e.detail.value[2]
    ]
  })

  setTimeout(() => {
    this.setState({
      value: [2, 2, 2]
    })
  }, 0)
}

@Chen-jj
Copy link
Contributor

Chen-jj commented Mar 1, 2019

#1981

@taro-bot
Copy link

taro-bot bot commented Mar 15, 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
question Further information is requested
Projects
None yet
Development

No branches or pull requests

3 participants