小程序
小游戏
企业微信
微信支付
扫描小程序码分享
如根据经验在多少的范围内是某个等级和图标? 0-100经验 = 新手 + 新手图标, 101-200经验 = 初级 + 初级图标 ,201-300经验 = 中级 + 中间图标,请教各位大神我应该怎么写?
5 个回答
加粗
标红
插入代码
插入链接
插入图片
上传视频
let num,level,imgUrl,name
if(num< 100){
name="新手"
imgUrl="新手图标地址"
}else if(num > 100 && num <200){
name="初级"
imgUrl="初级图标地址"
}.............后面就这样写
你好,麻烦通过点击下方“反馈信息”按钮,提供出现问题的。
game(){
if(0 < 100){
}else if(0 > 100 && 101 <200){
}
你如果要根据经验判断的话,要把经验传进去啊。
game(experience){
....
if (experience < 100) {...}
else if (experience < 200) {...}
Page({
data: {
fuzhi:[], //首页传递过来赋值的数值
},
onLoad:function(options) {
console.log(JSON.parse(decodeURIComponent(options.shangpinbiao)))
var fuzhi = JSON.parse(decodeURIComponent(options.shangpinbiao))
this.setData({
fuzhi: fuzhi
})
Tztcii: function(e){
console.log(this.data.fuzhi)
var fuzhi = this.data.fuzhi
wx.navigateTo({
url: '../yxjd/yxjd?fuzhi='+encodeURIComponent(JSON.stringify(fuzhi))
let jy = this.data.fuzhi[0].experience;
if(jy < 100){
imgurl="https://gimg2.baidu.com/image_search/src=http%3A%2F%2Fimgx.xiawu.com%2Fxzimg%2Fi4%2F58639771%2FTB2byEBopXXXXXlXXXXXXXXXXXX_%21%2158639771.jpg&refer=http%3A%2F%2Fimgx.xiawu.com&app=2002&size=f9999,10000&q=a80&n=0&g=0n&fmt=auto?sec=1660575882&t=4b849426a5bb6eb6bf715848012cb52b"
}else if(jy < 200){
imgurl="cloud://cloud1-5gd336ao7658dc03.636c-cloud1-5gd336…/2022-07-14/fd0frcqqssbdmajlv2smgoeovtd3htko_.png"
fuzhi:[]
var fuzhi = this.transfrom(JSON.parse(decodeURIComponent(options.shangpinbiao)))
console.log(fuzhi.qqaccount)
transfrom(fuzhi){
fuzhi.forEach(element => {
if (element.experience <= 456){
element.level = '列兵1'
element.pic = 'https://636c-cloud1-5gd336ao7658dc03-1311702398.tcb.qcloud.la/CF/%E5%9B%BE%E6%A0%87/%E7%AC%91%E8%84%B8.png?sign=af9a89824976a107589c307e93d0eb20&t=1658109868'
}else if (element.experience <= 8026911){
element.level = '大校 1'
element.pic = 'https://636c-cloud1-5gd336ao7658dc03-1311702398.tcb.qcloud.la/CF/%E5%9B%BE%E6%A0%87/%E5%A4%A7%E6%A0%A11.jpg?sign=b0d3f96e21560a8e6596e007864b4e58&t=1658110080'
}else if (element.experience <= 8481771){
element.level = '大校 2'
element.pic = 'https://636c-cloud1-5gd336ao7658dc03-1311702398.tcb.qcloud.la/CF/%E5%9B%BE%E6%A0%87/%E5%A4%A7%E6%A0%A12.jpg?sign=7625a6473686e497d37bfd00329b8923&t=1658110066'
}else if (element.experience <= 8964561){
element.level = '大校 3'
element.pic = 'https://636c-cloud1-5gd336ao7658dc03-1311702398.tcb.qcloud.la/CF/%E5%9B%BE%E6%A0%87/%E5%A4%A7%E6%A0%A13.jpg?sign=362bff1bb2bdbfcf8257944703635076&t=1658110201'
}else if (element.experience <= 9475851){
element.level = '大校 4'
element.pic = 'https://636c-cloud1-5gd336ao7658dc03-1311702398.tcb.qcloud.la/CF/%E5%9B%BE%E6%A0%87/%E5%A4%A7%E6%A0%A14.jpg?sign=75d07653445bdb6e8232e4118a7d4958&t=1658110214'
}else if (element.experience <= 10016211){
element.level = '大校 5'
element.pic = 'https://636c-cloud1-5gd336ao7658dc03-1311702398.tcb.qcloud.la/CF/%E5%9B%BE%E6%A0%87/%E5%A4%A7%E6%A0%A15.jpg?sign=5dcf54e518c89ca1a3b46d2dabddb575&t=1658110226'
}else if (element.experience <= 10586211){
element.level = '大校 6'
element.pic = 'https://636c-cloud1-5gd336ao7658dc03-1311702398.tcb.qcloud.la/CF/%E5%9B%BE%E6%A0%87/%E5%A4%A7%E6%A0%A16.jpg?sign=a6f217263939fff6dbf7e98c8f83d1bd&t=1658110235'
}else if (element.experience <= 11186421){
element.level = '少将 1'
js定义一个方法:对经验值进行分等级判断
1、if else
2、wxs :https://developers.weixin.qq.com/miniprogram/dev/reference/wxs/01wxs-module.html
关注后,可在微信内接收相应的重要提醒。
请使用微信扫描二维码关注 “微信开放社区” 公众号
let num,level,imgUrl,name
if(num< 100){
name="新手"
imgUrl="新手图标地址"
}else if(num > 100 && num <200){
name="初级"
imgUrl="初级图标地址"
}.............后面就这样写
换写法是这样吗?
game(){
let num,level,imgUrl,name
if(0 < 100){
name="新手"
imgUrl="新手图标地址"
}else if(0 > 100 && 101 <200){
name="初级"
imgUrl="初级图标地址"
}
}
你如果要根据经验判断的话,要把经验传进去啊。
game(experience){
....
if (experience < 100) {...}
else if (experience < 200) {...}
}
Page({
data: {
fuzhi:[], //首页传递过来赋值的数值
},
onLoad:function(options) {
console.log(JSON.parse(decodeURIComponent(options.shangpinbiao)))
var fuzhi = JSON.parse(decodeURIComponent(options.shangpinbiao))
this.setData({
fuzhi: fuzhi
})
},
Tztcii: function(e){
console.log(this.data.fuzhi)
var fuzhi = this.data.fuzhi
wx.navigateTo({
url: '../yxjd/yxjd?fuzhi='+encodeURIComponent(JSON.stringify(fuzhi))
})
},
game(){
let jy = this.data.fuzhi[0].experience;
if(jy < 100){
name="新手"
imgurl="https://gimg2.baidu.com/image_search/src=http%3A%2F%2Fimgx.xiawu.com%2Fxzimg%2Fi4%2F58639771%2FTB2byEBopXXXXXlXXXXXXXXXXXX_%21%2158639771.jpg&refer=http%3A%2F%2Fimgx.xiawu.com&app=2002&size=f9999,10000&q=a80&n=0&g=0n&fmt=auto?sec=1660575882&t=4b849426a5bb6eb6bf715848012cb52b"
}else if(jy < 200){
name="初级"
imgurl="cloud://cloud1-5gd336ao7658dc03.636c-cloud1-5gd336…/2022-07-14/fd0frcqqssbdmajlv2smgoeovtd3htko_.png"
}
}
})
参考一下:https://developers.weixin.qq.com/s/rWA91OmY7LA1
PS:找本JS书啃一啃吧。。
PS:在努力。。。
先用JS处理了数据,你看看。
Page({
data: {
fuzhi:[]
},
onLoad:function(options) {
console.log(JSON.parse(decodeURIComponent(options.shangpinbiao)))
var fuzhi = this.transfrom(JSON.parse(decodeURIComponent(options.shangpinbiao)))
this.setData({
fuzhi: fuzhi
})
console.log(fuzhi.qqaccount)
},
transfrom(fuzhi){
fuzhi.forEach(element => {
if (element.experience <= 456){
element.level = '列兵1'
element.pic = 'https://636c-cloud1-5gd336ao7658dc03-1311702398.tcb.qcloud.la/CF/%E5%9B%BE%E6%A0%87/%E7%AC%91%E8%84%B8.png?sign=af9a89824976a107589c307e93d0eb20&t=1658109868'
}else if (element.experience <= 8026911){
element.level = '大校 1'
element.pic = 'https://636c-cloud1-5gd336ao7658dc03-1311702398.tcb.qcloud.la/CF/%E5%9B%BE%E6%A0%87/%E5%A4%A7%E6%A0%A11.jpg?sign=b0d3f96e21560a8e6596e007864b4e58&t=1658110080'
}else if (element.experience <= 8481771){
element.level = '大校 2'
element.pic = 'https://636c-cloud1-5gd336ao7658dc03-1311702398.tcb.qcloud.la/CF/%E5%9B%BE%E6%A0%87/%E5%A4%A7%E6%A0%A12.jpg?sign=7625a6473686e497d37bfd00329b8923&t=1658110066'
}else if (element.experience <= 8964561){
element.level = '大校 3'
element.pic = 'https://636c-cloud1-5gd336ao7658dc03-1311702398.tcb.qcloud.la/CF/%E5%9B%BE%E6%A0%87/%E5%A4%A7%E6%A0%A13.jpg?sign=362bff1bb2bdbfcf8257944703635076&t=1658110201'
}else if (element.experience <= 9475851){
element.level = '大校 4'
element.pic = 'https://636c-cloud1-5gd336ao7658dc03-1311702398.tcb.qcloud.la/CF/%E5%9B%BE%E6%A0%87/%E5%A4%A7%E6%A0%A14.jpg?sign=75d07653445bdb6e8232e4118a7d4958&t=1658110214'
}else if (element.experience <= 10016211){
element.level = '大校 5'
element.pic = 'https://636c-cloud1-5gd336ao7658dc03-1311702398.tcb.qcloud.la/CF/%E5%9B%BE%E6%A0%87/%E5%A4%A7%E6%A0%A15.jpg?sign=5dcf54e518c89ca1a3b46d2dabddb575&t=1658110226'
}else if (element.experience <= 10586211){
element.level = '大校 6'
element.pic = 'https://636c-cloud1-5gd336ao7658dc03-1311702398.tcb.qcloud.la/CF/%E5%9B%BE%E6%A0%87/%E5%A4%A7%E6%A0%A16.jpg?sign=a6f217263939fff6dbf7e98c8f83d1bd&t=1658110235'
}else if (element.experience <= 11186421){
element.level = '少将 1'
js定义一个方法:对经验值进行分等级判断
1、if else
2、wxs :https://developers.weixin.qq.com/miniprogram/dev/reference/wxs/01wxs-module.html