index.js
1.6 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
const app = getApp()
Page({
data: {
str: '你猜',
multiArray: [], // 二维数组数据
arr1: ['a', 'b', 'c'],
arr2: [
[1, 2, 3],
[4, 5, 6],
[7, 8, 9]
],
multiIndex: [0, 0], // 默认的下标
},
start() {
let arr1 = this.data.arr1
let arr2 = this.data.arr2
this.setData({
multiArray: [arr1, arr2[0]]
})
},
change(e) {
console.log(e.detail)
let column = e.detail.column
let data = {
multiIndex: this.data.multiIndex,
multiArray: this.data.multiArray
}
data.multiIndex[column] = e.detail.value;
switch (column) {
case 0:
data.multiArray[1] = this.data.arr2[e.detail.value]
data.multiIndex[1] = 0
break;
}
this.setData(data)
},
get_str(e) {
console.log(e)
let index1 = e.detail.value[0]
let index2 = e.detail.value[1]
let str2 = this.data.arr2[index1][index2]
console.log(str2)
this.setData({
str: str2
})
},
onLoad: function() {
this.start()
},
})