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 ;
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语言的数组差别好大,求解答,谢谢!
let ret = {
sum0: this.data.ne_1.slice(0,5),
sum1: this.data.ne_2.slice(0,3),
sum2: this.data.ne_3.slice(0,2),
sum3: this.data.ne_4.slice(0,3),
sum4: this.data.ne_5.slice(0,2),
}
this.setData({
ne_final:ret,
sum0: ret.sum0.length+ret.sum1.length+ret.sum2.length+ret.sum3.length+ret.sum4.length
})
let ret = [
this.data.ne_1.slice(0,5),
this.data.ne_2.slice(0,3),
this.data.ne_3.slice(0,2),
this.data.ne_4.slice(0,3),
this.data.ne_5.slice(0,2),
]
this.setData({
ne_final:ret
})