小程序-循環遍利數據

  1. school.js
Page({
    data:{
      arr: [
        {
          "id": "1001",
          "school": "廣州XXX1001學院"
        },
        {
          "id": "1002",
          "school": "廣州XXX1002學院"
        },
        {
          "id": "1003",
          "school": "廣州XXX1003學院"
        },
        {
          "id": "1004",
          "school": "廣州XXX1004學院"
        },
        {
          "id": "1005",
          "school": "廣州XXX1005學院"
        },
        {
          "id": "1006",
          "school": "廣州XXX1006學院"
        },
        {
          "id": "1007",
          "school": "廣州XXX1007學院"
        },
        {
          "id": "1008",
          "school": "廣州XXX1008學院"
        },
        {
          "id": "1009",
          "school": "廣州XXX1009學院"
        },
        {
          "id": "10010",
          "school": "廣州XXX10010學院"
        },
        {
          "id": "10011",
          "school": "廣州XXX10011學院"
        },
        {
          "id": "10012",
          "school": "廣州XXX10012學院"
        }
      ]
    },
    getschoolid: function (e) {
      var sId = e.target.id;
      console.log('保存學校id:' + sId);
      wx.setStorage({
        key: "schoolId",
        data: sId
      })
//    檢測設置成功執行跳轉
      wx.getStorage({
        key: 'schoolId',
        success: function (res) {


            //跳轉到成功頁面
          wx.switchTab({
              url: '../home/home'
            })
            console.log(2222);
        }
      })
    }, onReady: function () {


    },
    onLoad: function(options) {
      var that = this;
      var arrs = that.data.arr;
      that.setData({
        schoollist: arrs
      })

      console.log(21212);
      console.log(arrs);
      console.log(21212);
    }


})
  1. school.xml
<view class="indexs-box">選擇校園</view>   
<view wx:for="{{schoollist}}" wx:key="{{index}}" class="xuexiao" >
<button bindtap="getschoolid" id='{{item.id}}' >{{item.school}}</button> 
</view>
發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章