UNPKG

7.15 kBMarkdownView Raw
1# Tree
2
3### Basic usage
4
5:::kview
6
7```html
8<template>
9 <k-tree
10 v-model="selectValue"
11 :show-checkbox="showCheckbox"
12 :only-leaf="onlyLeaf"
13 :multiple="multiple"
14 :label-key="labelKey"
15 :value-key="valueKey"
16 :data-source="list"
17 @on-toggle-expand="toggleExpand"
18 @on-select-change="selectChange"
19 @on-check-change="checkChange"
20 />
21 <div class="attrs-box">
22 <button class="btn" @click="onlyLeaf=!onlyLeaf"> onlyLeaf : {{onlyLeaf}}</button>
23 <button class="btn" @click="showCheckbox = !showCheckbox"> showCheckbox : {{showCheckbox}}</button>
24 <button class="btn" @click="multiple = !multiple;showCheckbox = false">multiple select mode (showCheckbox should be false)-> multiple : {{multiple}} </button>
25 </div>
26 <div class="data-box">
27 <p>v-model -> {{selectValue}}</p>
28 </div>
29</template>
30
31<script>
32
33
34 export default {
35 data() {
36 return {
37 onlyLeaf: true,
38 showCheckbox: true,
39 multiple: true,
40 defaultExpandAll: true,
41 list: [{
42 name: "Node-1",
43 pId: "341500000000000",
44 open: "False",
45 id: "341525000000000",
46 children: [
47 {
48 name: "Node-1-1",
49 pId: "341525000000000",
50 open: "False",
51 id: "341525100000000",
52 children: [{
53 name: "Node-1-1-1",
54 pId: "341525000000000",
55 open: "False",
56 id: "341525100000000"
57 },
58 {
59 name: "Node-1-1-2",
60 pId: "341525000000000",
61 open: "False",
62 id: "341525104000000"
63 },
64 ]
65 },
66 {
67 name: "Node-1-2",
68 pId: "341525000000000",
69 open: "False",
70 id: "341525104000000"
71 },
72 {
73 name: "Node-1-3",
74 pId: "341525000000000",
75 open: "False",
76 id: "341525105000000"
77 },
78 {
79 name: "Node-1-4",
80 pId: "341525000000000",
81 open: "False",
82 id: "341525106000000"
83 },
84 {
85 name: "Node-1-5-Overflow Content Node",
86 pId: "341525000000000",
87 open: "False",
88 id: "341525401000000"
89 }
90 ]
91 }],
92 showCheckBox: false,
93 type: 'select',
94 labelKey: "name",
95 valueKey: "id",
96 childrenKey: 'children',
97 selectValue: '341525401000000', // binding value
98 };
99 },
100 mounted() {
101 setTimeout(() => {
102 this.selectValue = "341525106000000";
103 }, 3000)
104 },
105 watch: {
106 selectValue() {
107 console.log('selectValue', this.selectValue);
108 },
109 },
110
111 methods: {
112 toggleExpand(node) {
113 console.log('toggleExpand', node);
114 },
115 selectChange(node) {
116 console.log('selectChange', node);
117 },
118 checkChange(nodes) {
119 console.log('checkChange', nodes);
120 },
121 }
122 };
123</script>
124
125<style>
126 .attrs-box {
127 margin: 10px;
128 }
129 .btn {
130 padding: 4px 10px;
131 color: #409eff;
132 background: #ecf5ff;
133 border-color: #b3d8ff;
134 display: inline-block;
135 line-height: 1;
136 white-space: nowrap;
137 cursor: pointer;
138 background: #fff;
139 border: 1px solid #dcdfe6;
140 color: #606266;
141 -webkit-appearance: none;
142 text-align: center;
143 box-sizing: border-box;
144 outline: none;
145 margin: 0;
146 transition: .1s;
147 font-weight: 500;
148 -moz-user-select: none;
149 -webkit-user-select: none;
150 -ms-user-select: none;
151 padding: 12px 20px;
152 font-size: 14px;
153 border-radius: 4px;
154 }
155
156 .data-box p {
157 margin: 10px;
158 }
159</style>
160```
161
162:::
163
164## Attributes
165
166<div class="markdown-table">
167
168| Attribute | Description | Type|Accepted Value|Default|Require|
169|-------|---------|---|---|---|---|
170|dataSource|tree data| Array | - |- |true|
171|width|node content width (unit: px)|Number| -|260|-|
172|position|position of node's Tip|string|top、left、right、bottom|top|-|
173|labelKey|specify which key of node object is used as the node's label|String| -|label|true
174|valueKey|specify which key of node object is used as the node's value (return node object when it's empty)|String|-|value|-|
175|childrenKey|specify which node object is used as the node's subtree|String|-|children|-|
176|v-model|binding value , ` valueKey field is required; string composed of the value of the object's valueKey and the comma ` |String|-|-|-|
177|multiple|单击多选|-|-|-|-|
178|only-leaf|only binding leaf node value|-|-|-|-|
179|show-checkbox|whether node is selectable|-|-|-|-|
180|props|configuration dataSource options, see the following table|-|-|-|-|
181
182</div>
183
184## Props
185
186<div class="markdown-table">
187
188| Attribute | Description | Type | Default| Require|
189|-------|---------|------|--------|----------|
190|selected|node selected|Boolean|-|-
191|checked|node checked|Boolean|-|-
192|expand|node expanded|Boolean|-|-
193
194</div>
195
196## Events
197
198<div class="markdown-table">
199
200| Event Name | Description | Attribute|
201| ------ |----- | ---- |
202|on-toggle-expand|triggers when current node open|parameter: node ( `expand`
203|on-select-change|(`show-checkbox is false`)triggers when the selected state of the node changes|paramter: the currently selected array of nodes |
204|on-check-change|(`show-checkbox is true`)triggers when the checked state of the node changes|paramter: the currently checked array of nodes |
205
206</div>
207
208### methods
209
210<div class="markdown-table">
211
212| Event Name | Description | Attribute|
213| ------ |----- | ---- |
214|getSelectedNodes|(`show-checkbox is false`)If the node can be selected , it returns the currently selected array of nodes|-|
215|getCheckedNodes|(`show-checkbox is true`)If the node can be checked , it returns the currently checked array of nodes|-|
216
217</div>
218