小程序-使用picker綁定數組對象


實現效果:

 當點擊廠區名稱時,彈出選項:

 並將公司的id存儲下來,代碼如下:

選擇廠區的頁面代碼:

    <!--選擇廠區-->
    <view class="pickerView">
      <view>
        <image class="keyImage" src="../../icons/corp.png"></image>
        <label class="loginLab">廠區</label>
      </view>
      <picker class="pickerBox" bindchange="bindPickerChange" value="{{index}}" range="{{corpArray}}" range-key="name">
        <view class="picker">
          <image class="keyImage" src="../../icons/trangle.png"></image>
          {{corpArray[index].name}}
        </view>
      </picker>
    </view>

相關js代碼:

  data: {
    corpArray: [
      {
        corpid: "T",
        name: 'A有限公司'
      },
      {
        corpid: "L",
        name: 'B有限公司'
      },
      {
        corpid: "N",
        name: 'C有限公司'
      }
    ],
    corpid: "T", // 選擇的廠區
    index: 0,
  },
  bindPickerChange: function (e) {
    var temp = this.data.corpArray[e.detail.value].corpid;
    this.setData({
      index: e.detail.value,
      corpid: temp
    })
  },

以上;


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM