问题,关于老师说的使用switch
问题描述:
请老师帮我检查一下,为什么我改用 switch 显示不出数据,传的值也都能打印出来,可是最后的结果还是空的
相关截图:
相关代码:
// pages/hot/hot.js
Page({
data: {
rankType: undefined,
rankTitle: [{
name: '实战排行',
type: 'project'
},
{
name: '路径排行',
type: 'path'
}
],
timeType: undefined,
timeTitle: [{
date: '周',
type: 'week'
},
{
date: '月',
type: 'month'
}
],
rankListData: []
},
rankList: {},
onLoad() {
wx.request({
url: 'https://www.fastmock.site/mock/55f026f87038d1b3db021a9276d04bb7/longzilei/api/rank',
success: (res) => {
// console.log(res)
const {
data: {
data
}
} = res
this.rankList = data
const rankType = wx.getStorageSync('rankType') || 'project'
const timeType = wx.getStorageSync('timeType') || 'week'
this.setData({
rankType,
timeType
})
this.rankDataChange(rankType, timeType)
}
})
},
rankDataChange(rankType, timeType) {
let list = []
console.log(rankType, timeType)
switch (rankType, timeType) {
case (rankType === 'project' && timeType === 'week'):
list = this.rankList.projectWeek
console.log(list)
break;
case (rankType === 'project' && timeType === 'month'):
list = this.rankList.projectMonth
break
case (rankType === 'path' && timeType === 'week'):
list = this.rankList.pathWeek
break
case (rankType === 'path' && timeType === 'month'):
list = this.rankList.pathMonth
break
}
// if (rankType === 'project' && timeType === 'week') {
// list = this.rankList.projectWeek
// } else if (rankType === 'project' && timeType === 'month') {
// list = this.rankList.projectMonth
// } else if (rankType === 'path' && timeType === 'week') {
// list = this.rankList.pathWeek
// } else {
// list = this.rankList.pathMonth
// }
console.log(list)
this.setData({
rankListData: list
})
},
rankChange(e) {
// console.log(e)
const rankType = e.currentTarget.dataset.rank
const {
timeType
} = this.data
// console.log(rankType)
this.setData({
rankType
})
wx.setStorage({
data: rankType,
key: 'rankType'
})
this.rankDataChange(rankType, timeType)
},
timeChange(e) {
const {
rankType
} = this.data
const timeType = e.currentTarget.dataset.time
this.setData({
timeType
})
wx.setStorage({
data: timeType,
key: 'timeType'
})
this.rankDataChange(rankType, timeType)
}
})
15
收起
正在回答 回答被采纳积分+1
2回答
恭喜解决一个难题,获得1积分~
来为老师/同学的回答评分吧
0 星