- 小程序获取了用户openid之后,怎么储存进全局变量?
求助!我获取了openid,怎么把它存到全局变量里啊?[图片]
2019-11-28 - 怎么将一个数组的某几项赋给另一个数组中的几项?
[代码]const db = wx.cloud.database({});[代码][代码]const cont = db.collection([代码][代码]'question_data'[代码][代码]);[代码] [代码]Page({[代码][代码] [代码][代码]data: {[代码][代码] [代码][代码]ne_1: [],[代码][代码] [代码][代码]ne_2: [],[代码][代码] [代码][代码]ne_3: [],[代码][代码] [代码][代码]ne_4: [],[代码][代码] [代码][代码]ne_5: [],[代码][代码] [代码][代码]ne_final: [],[代码][代码] [代码][代码]res: [代码][代码]null[代码][代码],[代码][代码] [代码][代码]sum0: 0,[代码][代码] [代码][代码]id: 0[代码][代码] [代码][代码]},[代码] [代码] [代码][代码]onLoad: [代码][代码]function[代码] [代码](options) {[代码][代码] [代码][代码]var[代码] [代码]_this = [代码][代码]this[代码][代码];[代码][代码] [代码][代码]const db = wx.cloud.database();[代码]//下面将5个数据库的记录(均小于20条)赋给5个数组 [代码] [代码][代码]db.collection([代码][代码]'question_group1'[代码][代码]).get({[代码][代码] [代码][代码]success: res => {[代码][代码] [代码][代码]console.log(res.data)[代码][代码] [代码][代码]this[代码][代码].setData({[代码][代码] [代码][代码]ne_1: res.data[代码][代码] [代码][代码]})[代码][代码] [代码][代码]}[代码][代码] [代码][代码]})[代码][代码] [代码] [代码] [代码][代码]db.collection([代码][代码]'question_group2'[代码][代码]).get({[代码][代码] [代码][代码]success: res => {[代码][代码] [代码][代码]console.log(res.data)[代码][代码] [代码][代码]this[代码][代码].setData({[代码][代码] [代码][代码]ne_2: res.data[代码][代码] [代码][代码]})[代码][代码] [代码][代码]}[代码][代码] [代码][代码]})[代码] [代码] [代码][代码]db.collection([代码][代码]'question_group3'[代码][代码]).get({[代码][代码] [代码][代码]success: res => {[代码][代码] [代码][代码]console.log(res.data)[代码][代码] [代码][代码]this[代码][代码].setData({[代码][代码] [代码][代码]ne_3: res.data[代码][代码] [代码][代码]})[代码][代码] [代码][代码]}[代码][代码] [代码][代码]})[代码] [代码] [代码][代码]db.collection([代码][代码]'question_group4'[代码][代码]).get({[代码][代码] [代码][代码]success: res => {[代码][代码] [代码][代码]console.log(res.data)[代码][代码] [代码][代码]this[代码][代码].setData({[代码][代码] [代码][代码]ne_4: res.data[代码][代码] [代码][代码]})[代码][代码] [代码][代码]}[代码][代码] [代码][代码]})[代码] [代码] [代码][代码]db.collection([代码][代码]'question_group5'[代码][代码]).get({[代码][代码] [代码][代码]success: res => {[代码][代码] [代码][代码]console.log(res.data)[代码][代码] [代码][代码]this[代码][代码].setData({[代码][代码] [代码][代码]ne_5: res.data[代码][代码] [代码][代码]})[代码][代码] [代码][代码]}[代码][代码] [代码][代码]})[代码] //每个数组取前i项赋给数组ne_final,最后的数组里需要20条记录 //下面是我写的错误的代码,怎么改都报错,不知道应该办 [代码] [代码][代码]for[代码] [代码](let i = 0; i < 6; i++) {[代码][代码] [代码][代码]this[代码][代码].setData({[代码][代码] [代码][代码]'ne_final[sum0]'[代码][代码]: [代码][代码]this[代码][代码].data.ne_1[i],[代码][代码] [代码][代码]sum0: [代码][代码]this[代码][代码].data.sum0 + 1[代码][代码] [代码][代码]})[代码][代码] [代码][代码]}[代码][代码] [代码][代码]for[代码] [代码](let i = 0; i < 4; i++) {[代码][代码] [代码][代码]this[代码][代码].setData({[代码][代码] [代码][代码]'ne_final[sum0]'[代码][代码]: [代码][代码]this[代码][代码].data.ne_2[i],[代码][代码] [代码][代码]sum0: [代码][代码]this[代码][代码].data.sum0 + 1[代码][代码] [代码][代码]})[代码][代码] [代码][代码]}[代码][代码] [代码][代码]for[代码] [代码](let i = 0; i < 3; i++) {[代码][代码] [代码][代码]this[代码][代码].setData({[代码][代码] [代码][代码]'ne_final[sum0]'[代码][代码]: [代码][代码]this[代码][代码].data.ne_3[i],[代码][代码] [代码][代码]sum0: [代码][代码]this[代码][代码].data.sum0 + 1[代码][代码] [代码][代码]})[代码][代码] [代码][代码]}[代码][代码] [代码][代码]for[代码] [代码](let i = 0; i < 4; i++) {[代码][代码] [代码][代码]this[代码][代码].setData({[代码][代码] [代码][代码]'ne_final[sum0]'[代码][代码]: [代码][代码]this[代码][代码].data.ne_4[i],[代码][代码] [代码][代码]sum0: [代码][代码]this[代码][代码].data.sum0 + 1[代码][代码] [代码][代码]})[代码][代码] [代码][代码]}[代码][代码] [代码][代码]for[代码] [代码](let i = 0; i < 3; i++) {[代码][代码] [代码][代码]this[代码][代码].setData({[代码][代码] [代码][代码]'ne_final[sum0]'[代码][代码]: [代码][代码]this[代码][代码].data.ne_5[i],[代码][代码] [代码][代码]sum0: [代码][代码]this[代码][代码].data.sum0 + 1[代码][代码] [代码][代码]})[代码][代码] [代码][代码]}[代码][代码] [代码][代码]},[代码]小程序新手,一直搞不懂数组,感觉和c语言的数组差别好大,求解答,谢谢!
2019-11-17 - 前端调用微信云开发数据库中的数据后,怎么逐条显示?(大一菜鸟,刚刚接触小程序开发,目前只能全部显示)
[代码]const db = wx.cloud.database({});[代码][代码]const cont = db.collection([代码][代码]'question_data'[代码][代码]);[代码] [代码]Page({[代码][代码] [代码][代码]data: {[代码][代码] [代码][代码]ne:[],[代码][代码] [代码][代码]res: [代码][代码]null[代码][代码],[代码][代码] [代码][代码]status: {[代码][代码] [代码][代码]A: [代码][代码]false[代码][代码],[代码][代码] [代码][代码]B: [代码][代码]false[代码][代码],[代码][代码] [代码][代码]C: [代码][代码]false[代码] [代码] [代码][代码]},[代码][代码] [代码][代码]show_flag: [代码][代码]false[代码][代码],[代码][代码] [代码][代码]id: 1,[代码][代码] [代码][代码]has_right: 0[代码][代码] [代码][代码]},[代码] [代码] [代码][代码]onLoad: [代码][代码]function[代码] [代码](options) {[代码][代码] [代码][代码]var[代码] [代码]_this = [代码][代码]this[代码][代码];[代码][代码] [代码][代码] const db = wx.cloud.database();[代码][代码] [代码][代码] db.collection([代码][代码]'question_data'[代码][代码]).get({[代码][代码] [代码][代码]success: res =>{[代码][代码] [代码][代码]console.log(res.data)[代码][代码] [代码][代码]this[代码][代码].setData({[代码][代码] [代码][代码]ne: res.data[代码][代码] [代码][代码]})[代码][代码] [代码][代码]}[代码][代码] [代码][代码]})[代码] [代码] [代码][代码]},[代码][代码]})[代码][代码]<[代码][代码]view[代码] [代码]class[代码][代码]=[代码][代码]'a'[代码] [代码]wx:for[代码][代码]=[代码][代码]"{{ne}}"[代码][代码]>[代码][代码]<[代码][代码]view[代码][代码]>{{item.id}}.{{item.question}}</[代码][代码]view[代码][代码]>[代码][代码]<[代码][代码]view[代码] [代码]bindtap[代码][代码]=[代码][代码]"choose"[代码] [代码]id[代码][代码]=[代码][代码]"A"[代码][代码]>A.{{item.A}}{{status.A?'v':''}}</[代码][代码]view[代码][代码]>[代码][代码]<[代码][代码]view[代码] [代码]bindtap[代码][代码]=[代码][代码]"choose"[代码] [代码]id[代码][代码]=[代码][代码]"B"[代码][代码]>B.{{item.B}}{{status.B?'v':''}}</[代码][代码]view[代码][代码]>[代码][代码]<[代码][代码]view[代码] [代码]bindtap[代码][代码]=[代码][代码]"choose"[代码] [代码]id[代码][代码]=[代码][代码]"C"[代码][代码]>C.{{item.C}}{{status.C?'v':''}}</[代码][代码]view[代码][代码]>[代码][代码]</[代码][代码]view[代码][代码]>[代码] [图片] [图片] 现在只能把所有记录一起显示出来,求教如何显示某一记录。(上百度也找不到解决方案,应该怎么办)
2019-11-11