Browse Source

修改下拉列表默认选项

zhang 5 years ago
parent
commit
d44bc9e14d
2 changed files with 70 additions and 63 deletions
  1. 34 27
      pages/select/select.vue
  2. 36 36
      static/test.js

+ 34 - 27
pages/select/select.vue

@@ -91,30 +91,36 @@
 
 		onLoad(options) {
 			// console.log(options)
-			var str = options.roomSelect;
-			var arr = new Array();
-			var i = 0;
-			while (i < str.length) {
-				var s = "";
-				while (str.charCodeAt(i) < 256) {
-					s = s + str.charAt(i);
-					i++;
-				}
-				arr.push(s);
-				var s = "";
-				while (str.charCodeAt(i) > 256) {
-					s = s + str.charAt(i);
-					i++;
-				}
-				arr.push(s);
-			}
-			for (i = 0; i < arr.length; i++) {
-				console.log(arr[i]);
-			}
-			
-			// 自动填充
+			var str = options.roomSelect.split("-");
+			// console.log(str[0])
+			// var arr = new Array();
+			// var i = 0;
+			// while (i < str.length) {
+			// 	var s = "";
+			// 	while (str.charCodeAt(i) < 256) {
+			// 		s = s + str.charAt(i);
+			// 		i++;
+			// 	}
+			// 	arr.push(s);
+			// 	var s = "";
+			// 	while (str.charCodeAt(i) > 256) {
+			// 		s = s + str.charAt(i);
+			// 		i++;
+			// 	}
+			// 	arr.push(s);
+			// }
+			// for (i = 0; i < arr.length; i++) {
+			// 	console.log(arr[i]);
+			// }
 			
 			
+			this.arr1 = [str[0]]
+			this.arr2 = [str[1]]
+			this.arr3 = [str[2]]
+			this.arr4 = [str[3]]
+
+			// 自动填充
+
 			this.nschool = this.allData.data.length
 		},
 
@@ -126,7 +132,7 @@
 				if (this.array2) {
 					this.array2 = []
 				}
-				
+
 				//获取选择器1的值
 				for (var i = 0; i < this.nschool; i++) {
 					// this.array1.push(this.allData.data[i].school)
@@ -135,7 +141,7 @@
 					if (!this.allData.data[i].builds) {
 						continue
 					}
-					
+
 					//获取选择器二中的值
 					if (i == this.index1) {
 						//得到选择器二中值的个数
@@ -161,14 +167,14 @@
 				if (this.array3) {
 					this.array3 = []
 				}
-				
+
 				for (var i = 0; i < this.nbuilds; i++) {
 					// this.array1.push(this.allData.data[i].school)
 					// console.log(this.allData.data[i].school)
 					if (!this.allData.data[this.index1].builds[i].floors) {
 						continue
 					}
-					
+
 					if (i == this.index2) {
 						this.floors = this.allData.data[this.index1].builds[i].floors.length
 						// console.log(this.floors)
@@ -250,7 +256,8 @@
 				//将选择器中的值加到变量room中,传到下一个页面
 				// this.room = this.room.concat(this.array1[this.index1], this.array2[this.index2], this.array3[this.index3],
 				// 	this.array4[this.index4]);
-				this.room = this.room.concat(this.array1[this.index1], this.array4[this.index4]);
+				this.room = this.room.concat(this.array1[this.index1] + '-' + this.array2[this.index2] + '-' + this.array3[
+					this.index3] +'-'+ this.array4[this.index4]);
 
 				this.dis_num5 = 0;
 

+ 36 - 36
static/test.js

@@ -1,11 +1,11 @@
 // const data = [{"黄家湖校区":[{
-// 		"1#":[{
+// 		"1":[{
 
 // 		}]
 // 	}]}
 // 	,
 // 	{"墨轩湖校区":[{
-// 			"1#":[{
+// 			"1":[{
 
 // 			}]
 // 		}]}
@@ -14,56 +14,56 @@
 const data = [{
 	"school": "黄家湖校区",
 	"builds": [{
-			"building": "1#",
+			"building": "1",
 			"floors": [{
 					"floor": "1层",
-					"rooms": [1101, 1102, 1103, 1104, 1105]
+					"rooms": ['01', '02', '03', '04', '05']
 				},
 				{
 					"floor": "2层",
-					"rooms": [1201, 1202, 1203, 1204, 1205]
+					"rooms": ['01', '02', '03', '04', '05']
 				}, {
 					"floor": "3层",
-					"rooms": [1301, 1302, 1303, 1304, 1305]
+					"rooms": ['01', '02', '03', '04', '05']
+				}, {
+					"floor": "4层",
+					"rooms": ['01', '02', '03', '04', '05']
 				}
 			]
 		},
 		{
-			"building": "2#",
+			"building": "2",
 			"floors": [{
 					"floor": "1层",
-					"rooms": [2101, 2102, 2103, 2104, 2105]
+					"rooms": ['01', '02', '03', '04', '05']
 				},
 				{
 					"floor": "2层",
-					"rooms": [2201, 2202, 2203, 2204, 2205]
+					"rooms": ['01', '02', '03', '04', '05']
 				}, {
 					"floor": "3层",
-					"rooms": [2301, 2302, 2303, 2304, 2305]
+					"rooms": ['01', '02', '03', '04', '05']
 				}, {
 					"floor": "4层",
-					"rooms": [2401, 2402, 2403, 2404, 2405]
+					"rooms": ['01', '02', '03', '04', '05']
 				}
 			]
 		},
 		{
-			"building": "3#",
+			"building": "3",
 			"floors": [{
 					"floor": "1层",
-					"rooms": [3101, 3102, 3103, 3104, 3105]
+					"rooms": ['01', '02', '03', '04', '05']
 				},
 				{
 					"floor": "2层",
-					"rooms": [3201, 3202, 3203, 3204, 3205]
+					"rooms": ['01', '02', '03', '04', '05']
 				}, {
 					"floor": "3层",
-					"rooms": [3301, 3302, 3303, 3304, 3305]
+					"rooms": ['01', '02', '03', '04', '05']
 				}, {
 					"floor": "4层",
-					"rooms": [3401, 3402, 3403, 3404, 3405]
-				}, {
-					"floor": "5层",
-					"rooms": [3501, 3502, 3503, 3504, 3505]
+					"rooms": ['01', '02', '03', '04', '05']
 				}
 			]
 		}
@@ -71,56 +71,56 @@ const data = [{
 }, {
 	"school": "墨轩湖校区",
 	"builds": [{
-			"building": "1#",
+			"building": "1",
 			"floors": [{
 					"floor": "1层",
-					"rooms": [1101, 1102, 1103, 1104, 1105]
+					"rooms": ['01', '02', '03', '04', '05']
 				},
 				{
 					"floor": "2层",
-					"rooms": [1201, 1202, 1203, 1204, 1205]
+					"rooms": ['01', '02', '03', '04', '05']
 				}, {
 					"floor": "3层",
-					"rooms": [1301, 1302, 1303, 1304, 1305]
+					"rooms": ['01', '02', '03', '04', '05']
+				}, {
+					"floor": "4层",
+					"rooms": ['01', '02', '03', '04', '05']
 				}
 			]
 		},
 		{
-			"building": "2#",
+			"building": "2",
 			"floors": [{
 					"floor": "1层",
-					"rooms": [2101, 2102, 2103, 2104, 2105]
+					"rooms": ['01', '02', '03', '04', '05']
 				},
 				{
 					"floor": "2层",
-					"rooms": [2201, 2202, 2203, 2204, 2205]
+					"rooms": ['01', '02', '03', '04', '05']
 				}, {
 					"floor": "3层",
-					"rooms": [2301, 2302, 2303, 2304, 2305]
+					"rooms": ['01', '02', '03', '04', '05']
 				}, {
 					"floor": "4层",
-					"rooms": [2401, 2402, 2403, 2404, 2405]
+					"rooms": ['01', '02', '03', '04', '05']
 				}
 			]
 		},
 		{
-			"building": "3#",
+			"building": "3",
 			"floors": [{
 					"floor": "1层",
-					"rooms": [3101, 3102, 3103, 3104, 3105]
+					"rooms": ['01', '02', '03', '04', '05']
 				},
 				{
 					"floor": "2层",
-					"rooms": [3201, 3202, 3203, 3204, 3205]
+					"rooms": ['01', '02', '03', '04', '05']
 				}, {
 					"floor": "3层",
-					"rooms": [3301, 3302, 3303, 3304, 3305]
+					"rooms": ['01', '02', '03', '04', '05']
 				}, {
 					"floor": "4层",
-					"rooms": [3401, 3402, 3403, 3404, 3405]
-				}, {
-					"floor": "5层",
-					"rooms": [3501, 3502, 3503, 3504, 3505]
+					"rooms": ['01', '02', '03', '04', '05']
 				}
 			]
 		}