- this.setData中怎样用push给数组赋值?
/*此处省略若干行代码*/ let UserArray = []; /*此处省略若干行代码*/ Page({ data: { /*此处省略若干行代码*/ userarray: UserArray, }, /*此处省略若干行代码*/ Func:function(){ /*此处省略若干行代码*/ userinfotmp = { nickname: res.content, hour: options.value1, minute: options.value2, second: options.value3, userid: id }; /*此处省略若干行代码*/ this.setData({ userarray: this.data.userarray.push(userinfotmp) }); /*此处省略若干行代码*/ } /*此处省略若干行代码*/ }) 请问this.setData中怎样用push给数组赋值?上述代码中 userarray: this.data.userarray.push(userinfotmp) 的写法是否正确?如果错误,应该怎么写?
2023-01-12 - 请问我的wxml文件中哪个地方错了,应该怎么改?
ranklist.js /** * 生命周期函数--监听页面加载 */ onLoad: function (options) { let that = this; let userinfotmp = new Array({ nickname: '', hour: 0, minute: 0, second: 0, userid: 0 }); AlreadyRank = app.globalData.alreadyrank; winorlose = app.globalData.winorlose; if((!AlreadyRank)&&(winorlose)){ id++; wx.showModal({// 模态对话框 title: '留下大名!', showCancel: false, editable: true, placeholderText: '请留下你的大名:', success: function (res) { if (res.confirm) { // res.content获取用户输入信息 if(res.content != ''){ that.setData({ userinfo: { nickname: res.content, hour: options.value1, minute: options.value2, second: options.value3, userid: id } }); userinfotmp = { nickname: res.content, hour: options.value1, minute: options.value2, second: options.value3, userid: id }; userarray.push(userinfotmp); } } } }); AlreadyRank = true; app.globalData.alreadyrank = AlreadyRank; }else{ TotalNum = app.globalData.totalnum; console.log("TotalNum="+TotalNum); that.setData({ userinfo: { nickname: userinfotmp.nickname, hour: userinfotmp.hour, minute: userinfotmp.minute, second: userinfotmp.second, userid: userinfotmp.userid } }); } }, ranklist.wxml <view class="container" wx:for="{{userarray}}" wx:for-index="index" wx:for-item="item" wx:key="item.userid"> <view class="cell">{{item.userid}}</view> <view class="cell">{{item.nickname}}</view> <view class="cell">{{item.hour}}:{{item.minute}}:{{item.second}}</view> </view> 现在的情况是:模态对话框输入nickname,点击确定后,页面上并不显示模态对话框的数据。请问我的wxml文件中哪个地方错了,应该怎么改?
2023-01-12 - wx.showModal的输入框内容res.content的值怎样导出来?
onLoad: function (options) { let tmp = '1'; let modal = wx.showModal({// 模态对话框 title: '留下大名!', showCancel: false, editable: true, placeholderText: '请留下你的大名:', success: function (res) { if (res.confirm) { // res.content获取用户输入信息 console.log('用户点击确定', res.content); tmp = res.content; } } }); this.setData({ nickname: tmp, hour: options.value1, minute: options.value2, second: options.value3, }); }, 如上所示,怎样把wx.showModal中的success()的参数res的属性content 的值导出来?用过return res.content,失败了;用这个tmp = res.content又失败了。请教懂这个的大侠,谢谢!
2023-01-03