JSDM

HTML

 
1
<select id="select"></select>
2
<h4>最终效果</h4>
3
<select>
4
  <option value="4" label="a/a-2/index"></option>
5
  <option value="6" label="a/a-3/index"></option>
6
  <option value="8" label="b/index"></option>
7
  <option value="9" label="c"></option>
8
</select>

CSS

xxxxxxxxxx
6
 
1
select{
2
  font-size: 16px;
3
  width: 200px;
4
  height: 36px;
5
  padding: 0 10px;
6
}
? ?
? ?
必须是有效的URL
+ 添加另一个资源

JS

xxxxxxxxxx
67
 
1
const _list = [{
2
  name: 'a',
3
  flag: 'directory',
4
  id: '1',
5
  parentId: 'head',
6
  child: [{
7
    name: 'a-1',
8
    flag: 'directory',
9
    id: '2',
10
    parentId: '1'
11
  }, {
12
    name: 'a-2',
13
    flag: 'directory',
14
    id: '3',
15
    parentId: '1',
16
    child: [{
17
      name: 'index',
18
      flag: 'page',
19
      id: '4',
20
      parentId: '3'
21
    }]
22
  }, {
23
    name: 'a-3',
24
    flag: 'directory',
25
    id: '5',
26
    parentId: '1',
27
    child: [{
28
      name: 'index',
29
      flag: 'page',
30
      id: '6',
31
      parentId: '5'
32
    }]
33
  }]
34
}, {
35
  name: 'b',
36
  flag: 'directory',
37
  id: '7',
38
  parentId: 'head',
39
  child: [{
40
    name: 'index',
41
    flag: 'page',
42
    id: '8',
43
    parentId: '7'
44
  }]
45
}, {
46
  name: 'c',
47
  flag: 'page',
48
  id: '9',
49
  parentId: 'head'
50
}]
51
let newList = []
52
const fn = (arr) => {
53
  arr.forEach(item => {
54
    if (item.flag === 'page') {
55
      newList.push({
56
        id: item.id,
57
        name: item.name
58
      })
59
    }
60
    item.child && item.child.length && fn(item.child)
61
  })
62
}
63
fn(_list)
64
const range = document.createRange();
65
newList.forEach(item => {
66
  document.getElementById('select').append(range.createContextualFragment(`<option value="${item.id}">${item.name}</option>`))
67
})
必须是有效的URL
+ 添加另一个资源
Close

文件管理 点击文件查看URL

图片

  1. 暂无文件

CSS

  1. 暂无文件

JavaScript

  1. 暂无文件

其他

  1. 暂无文件
拖动文件到上面的区域或者:
加载中 ..................