-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathti.html
84 lines (74 loc) · 2.36 KB
/
ti.html
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
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Document</title>
</head>
<script src="http://www.codefans.net/ajaxjs/jquery-1.6.2.min.js"></script>
<body>
<form name="form0" id="form0" >
<input type="file" name="file0" id="file0" multiple="multiple" />
<br>
<img src="" width="100" height="100" id="img0" >
</form>
<script>
$("#file0").change(function(){
var objUrl = getObjectURL(this.files[0]) ;
console.log("objUrl = "+objUrl) ;
if (objUrl) {
$("#img0").attr("src", objUrl) ;
}
}) ;
//取得该文件的url
function getObjectURL(file) {
var url = null ;
if (window.createObjectURL!=undefined) {
url = window.createObjectURL(file) ;
} else if (window.URL!=undefined) {
url = window.URL.createObjectURL(file) ;
} else if (window.webkitURL!=undefined) {
url = window.webkitURL.createObjectURL(file) ;
}
return url ;
}
</script>
</body>
<script>
// 这道面试题谁会,由 input 转换成 output:
let input = [
{ "id": "17", "caption": "颜色", "types": ["黑", "棕"] },
{ "id": "23", "caption": "材质", "types": ["牛皮"] },
{ "id": "24", "caption": "尺码", "types": ["40", "41", "42"] }
]
let output = [
{ "17": "黑", "23": "牛皮", "24": "40" },
{ "17": "黑", "23": "牛皮", "24": "41" },
{ "17": "黑", "23": "牛皮", "24": "42" },
{ "17": "棕", "23": "牛皮", "24": "40" },
{ "17": "棕", "23": "牛皮", "24": "41" },
{ "17": "棕", "23": "牛皮", "24": "42" }
]
function fn(input) {
let arr = []
for(let i = 0; i < input.length; i++) {
// console.log(input)
if(i === 0) {
arr =arr.concat(input[i].types.map(val =>{
return {[input[i].id] : val}
}))
}else {
input[i]['types'].forEach(element => {
arr = arr.concat(arr.map(val =>{
console.log(val, i, 'arr')
return {...val, [input[i].id]:element}
}))
});
}
}
// console.log(arr, 'arr')
}
// fn(input)
// inputfn(input)
</script>
</html>