- 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>