- WXML代码保存编译后模拟器无反应,如何解决?
初学云开发,在Index界面,编辑一个按钮,代码如下 <!--index.wxml--> <button type="primary" bindtap="getData">提取数据</button> [图片] // index.js // const app = getApp() const db=wx.cloud.database() Page({ data: { }, getData(){ }, 编译后没有报错,但是模拟器中也是一张白板,求解决办法。我用测试号编写的时候,模拟器功能是没问题的。 [图片]
2022-05-22 - JS文件中调用if语句,出现部分跳过执行的情况如何处理?
WXML中很简单 <view class="COptAdv_row" wx:for="{{COptAdv_List}}"> <view class="COptAdv_Item1">{{item.Adv_Item1}}</view> <view class="COptAdv_Dia1">{{item.Adv_Dia_Para1}}</view> <view class="COptAdv_Item2">{{item.Adv_Item2}}</view> <view class="COptAdv_Dia2">{{item.Adv_Dia_Para2}}</view> </view> JS中数据定义如下: data: { COptAdv_List:[ {Adv_Item1:"XM1:", Adv_Dia_Para1:0, Adv_Item2:"XBR1:", Adv_Dia_Para2:0}, {Adv_Item1:"XM2:", Adv_Dia_Para1:0, Adv_Item2:"XBR2:", Adv_Dia_Para2:0}, {Adv_Item1:"XM3:", Adv_Dia_Para1:0, Adv_Item2:"XBR3:", Adv_Dia_Para2:0}, {Adv_Item1:"XM4:", Adv_Dia_Para1:0, Adv_Item2:"XBR4:", Adv_Dia_Para2:0}, {Adv_Item1:"XM5:", Adv_Dia_Para1:0, Adv_Item2:"XBR5:", Adv_Dia_Para2:0}, {Adv_Item1:"XM6:", Adv_Dia_Para1:0, Adv_Item2:"XBR6:", Adv_Dia_Para2:0} ], XM_P:0, XBR_P:0, }, Onload里对其进行判断和赋值,程序写得冗长,的确没找到更好的判断方式 onLoad: function (options) { var i = 0 var length = this.data.COptAdv_List.length for (let i = 0; i < length; i++) { console.log(app.Input_Current1) this.setData({ XM_P:app.Input_Current1[i]/app.Input_Parameter.Temp_Para/app.Input_Parameter.Density_Para, XBR_P:app.Input_Current1[i+6]/app.Input_Parameter.Temp_Para/app.Input_Parameter.Density_Para, }) console.log(i) console.log(this.data.XM_P) console.log(this.data.XBR_P) // 动力线选线径 if (this.data.XM_P>=0 && this.data.XM_P<=6) { this.setData({ [`COptAdv_List[${i}].Adv_Dia_Para1`]:0.25, }) } if (this.data.XM_P>6 && this.data.XM_P<=7) { this.setData({ [`COptAdv_List[${i}].Adv_Dia_Para1`]:0.35, }) } if (this.data.XM_P>7 && this.data.XM_P<=9) { this.setData({ [`COptAdv_List[${i}].Adv_Dia_Para1`]:0.5, }) } if (this.data.XM_P>9 && this.data.XM_P<=12) { this.setData({ [`COptAdv_List[${i}].Adv_Dia_Para1`]:0.75, }) } if (this.data.XM_P>12 && this.data.XM_P<=15) { this.setData({ [`COptAdv_List[${i}].Adv_Dia_Para1`]:1.0, }) } if (this.data.XM_P>15 && this.data.XM_P<=18) { this.setData({ [`COptAdv_List[${i}].Adv_Dia_Para1`]:1.5, }) } if (this.data.XM_P>18 && this.data.XM_P<=26) { this.setData({ [`COptAdv_List[${i}].Adv_Dia_Para1`]:2.5, }) } if (this.data.XM_P>26 && this.data.XM_P<=34) { this.setData({ [`COptAdv_List[${i}].Adv_Dia_Para1`]:4.0, }) } if (this.data.XM_P>34 && this.data.XM_P<=44) { this.setData({ [`COptAdv_List[${i}].Adv_Dia_Para1`]:6.0, }) } if (this.data.XM_P>44 && this.data.XM_P<=61) { this.setData({ [`COptAdv_List[${i}].Adv_Dia_Para1`]:10.0, }) } if (this.data.XM_P>61 && this.data.XM_P<=82) { this.setData({ [`COptAdv_List[${i}].Adv_Dia_Para1`]:16.0, }) } if (this.data.XM_P>82 && this.data.XM_P<=108) { this.setData({ [`COptAdv_List[${i}].Adv_Dia_Para1`]:25.0, }) } if (this.data.XM_P>108 && this.data.XM_P<=135) { this.setData({ [`COptAdv_List[${i}].Adv_Dia_Para1`]:35.0, }) } } // 抱闸线选线径 if (this.data.XBR_P>=0 && this.data.XBR_P<=6) { this.setData({ [`COptAdv_List[${i}].Adv_Dia_Para2`]:0.25, }) } if (this.data.XBR_P>6 && this.data.XBR_P<=7) { this.setData({ [`COptAdv_List[${i}].Adv_Dia_Para2`]:0.35, }) } if (this.data.XBR_P>7 && this.data.XBR_P<=9) { this.setData({ [`COptAdv_List[${i}].Adv_Dia_Para2`]:0.5, }) } if (this.data.XBR_P>9 && this.data.XBR_P<=12) { this.setData({ [`COptAdv_List[${i}].Adv_Dia_Para2`]:0.75, }) } if (this.data.XBR_P>12 && this.data.XBR_P<=15) { this.setData({ [`COptAdv_List[${i}].Adv_Dia_Para2`]:1.0, }) } if (this.data.XBR_P>15 && this.data.XBR_P<=18) { this.setData({ [`COptAdv_List[${i}].Adv_Dia_Para2`]:1.5, }) } if (this.data.XBR_P>18 && this.data.XBR_P<=26) { this.setData({ [`COptAdv_List[${i}].Adv_Dia_Para2`]:2.5, }) } if (this.data.XBR_P>26 && this.data.XBR_P<=34) { this.setData({ [`COptAdv_List[${i}].Adv_Dia_Para2`]:4.0, }) } if (this.data.XBR_P>34 && this.data.XBR_P<=44) { this.setData({ [`COptAdv_List[${i}].Adv_Dia_Para2`]:6.0, }) } if (this.data.XBR_P>44 && this.data.XBR_P<=61) { this.setData({ [`COptAdv_List[${i}].Adv_Dia_Para2`]:10.0, }) } if (this.data.XBR_P>61 && this.data.XBR_P<=82) { this.setData({ [`COptAdv_List[${i}].Adv_Dia_Para2`]:16.0, }) } if (this.data.XBR_P>82 && this.data.XBR_P<=108) { this.setData({ [`COptAdv_List[${i}].Adv_Dia_Para2`]:25.0, }) } if (this.data.XBR_P>108 && this.data.XBR_P<=135) { this.setData({ [`COptAdv_List[${i}].Adv_Dia_Para2`]:35.0, }) } }, 监控控制台,从数据提取到数据计算都没有问题 [图片] 但是if判断的时候就有问题了,数组中第2列比较和赋值都正常;第4列中,1个正常,5个不正常,求大神指点这种情况怎么处理? [图片]
2022-05-12 - Only digits (0-9) can be put inside[],${}无法解决,求指点?
WXML文件是这样的 <view class="XXX" wx:for="{{YY}}"> <view class="xx1">{{item.Y1}}</view> <view class="xx2">{{item.Y2}}</view> <view class="xx3">{{item.Y3}}</view> <icon class="xx4" wx:if="{{item.Y4}}" type="success" size="23"></icon> <icon class="xx4" wx:else type="warn" size="23"></icon> </view> JS文件里这样写的 data: { name_Items:['XM1','XM2','XM3','XM4','XM5','XM6','XBR1','XBR2','XBR3','XBR4','XBR5','XBR6'], YY:[ {Y1:'', Y2:0, Y3:0, Y4:false}, {Y1:'', Y2:0, Y3:0, Y4:false}, {Y1:'', Y2:0, Y3:0, Y4:false}, {Y1:'', Y2:0, Y3:0, Y4:false}, {Y1:'', Y2:0, Y3:0, Y4:false}, {Y1:'', Y2:0, Y3:0, Y4:false}, {Y1:'', Y2:0, Y3:0, Y4:false}, {Y1:'', Y2:0, Y3:0, Y4:false}, {Y1:'', Y2:0, Y3:0, Y4:false}, {Y1:'', Y2:0, Y3:0, Y4:false}, {Y1:'', Y2:0, Y3:0, Y4:false}, {Y1:'', Y2:0, Y3:0, Y4:false} ], }, 赋值语句是这么写的(注释中的语句是可以赋值成功的,但是放到for列表循环中就会报错) onLoad: function (options) { // this.setData({ // 'YY[0].Y1':this.data.name_Items[0], // 'YY[1].Y1':this.data.name_Items[1], // 'YY[2].Y1':this.data.name_Items[2], // 'YY[3].Y1':this.data.name_Items[3], // 'YY[4].Y1':this.data.name_Items[4], // 'YY[5].Y1':this.data.name_Items[5], // }) var i = 0 var length = this.data.name_Items.length for (let i = 0; i < length; i++) { console.log(i) this.setData({ ['YY[${i}].Y1']:this.data.name_Items[i], }) } }, 报错Error: Only digits (0-9) can be put inside [] in the path string: YY[${i}].Y1 [图片]
2022-05-11