- 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);
}
})
- 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>