picker的示例代码有问题
发布于 5 年前 作者 xiulanye 14597 次浏览 来自 问答
<view class="section">
  <view class="section__title">普通选择器</view>
  <picker bindchange="bindPickerChange" value="{{index}}" range="{{array}}">
    <view class="picker">
      当前选择:{{array[index]}}    </view>
  </picker></view><view class="section">
 data: {
    array: ['美国', '中国', '巴西', '日本'],
    objectArray: [
      {
        id: 0,
        name: '美国'
      },
      {
        id: 1,
        name: '中国'
      },
      {
        id: 2,
        name: '巴西'
      },
      {
        id: 3,
        name: '日本'
      }
    ],
    index: 0,
bindPickerChange: function(e) {    console.log('picker发送选择改变,携带值为', e.detail.value)    this.setData({
      index: e.detail.value
    })
  },

提交表单的时候picker的value初始值是number 0,但是改变以后的值是string ‘0’ ‘1’ ‘2’ ‘3’

回到顶部