当前位置:网站首页>Elemntui's select+tree implements the search function
Elemntui's select+tree implements the search function
2022-06-25 12:46:00 【fortunate_ leixin】
demand :
1, Click drop down , The tree structure appears , Check echo in select In the box
2, You can click Cancel , To choose ,
3, Support in select Match the input words in 

The front-end code :
<el-col :span="12">
<el-form-item label=" department " prop="deptName">
<el-select id="deptNameId"
v-model="certificateValue.deptName"
placeholder=" Please select "
filterable
:filter-method="filterTreeDate"
@visible-change="changeValue($event)">
<el-option
style="height: auto"
value="deptName"
>
<el-tree
ref="treeForm"
:data="treeDatalist"
:props="defaultProps"
default-expand-all
node-key="id"
show-checkbox
check-strictly
:filter-node-method="filterNode"
@check="handleCheckChange"
/>
</el-option>
</el-select>
</el-form-item>
</el-col>
data:
data(){
return{
certificateValue: {
deptName: '',
deptId: ''
}
}
}
methods:
methods:{
// This method is a custom search method ,api In the introduction ,
// It should be noted that , Also set filterable attribute , This attribute means that the search function is enabled
filterTreeDate(val) {
this.certificateValue.dept = val
this.$refs.treeForm.filter(val)
},
/** * The method for Tree Node filtering method , When you need to filter nodes , call Tree Example of filter Method , The parameter is keyword . It should be noted that , You need to set filter-node-method, Value is required Filtered value , It can be understood as the value passed by the page . * @param value * @param data * @returns {boolean} */
filterNode(value, data) {
if (!value) return true
return data.label.indexOf(value) !== -1
},
/** * The method for select The method triggered when the drop-down box of appears or hides , It appears as true, Hidden as false, This is to solve the problem when there are filter conditions , Click the drop-down again , The problem is that the data filtered last time is not all the data , So when I was hiding , Empty the filter conditions , This can avoid the problem that the data is still the data filtered last time When we click the drop-down again , What appears is all the data * @param val */
changeValue(val) {
if (!val) {
this.$refs.treeForm.filter('')
}
},
/** * Triggered when the check box is clicked , Passed two objects * In turn : * Pass to data The object corresponding to the node in the array of property 、 Tree currently selected objects , * The currently selected state object of the tree contains checkedNodes、checkedKeys、 halfCheckedNodes、halfCheckedKeys Four properties * @param data * @param checked */
handleCheckChange(data, checked) {
this.certificateValue.deptName = data.label
this.certificateValue.deptId = data.id
if (checked.checkedKeys !== '') {
this.checkedId = data.id
/** * adopt keys Set the currently selected node , * It should be noted that the method must be set node-key attribute * This method takes two parameters , * 1. Check the... Of the node key Array of * 2. boolean Parameters of type , * If the parameter is true Then only the selected state of the leaf node is set , * The default value is false */
this.$refs.treeForm.setCheckedKeys([data.id], true)
} else {
this.$refs.treeForm.setCheckedKeys([])
}
},
}
边栏推荐
- 地理空间搜索:kd树的实现原理
- Match regular with fixed format beginning and fixed end
- Initialize the project using the express framework
- (2) Pyqt5 tutorial -- > using qtdesigner to separate interface code
- C program linking SQLSERVER database: instance failed
- 使用Visio画立方体
- Why are databases cloud native?
- Go defer little knowledge
- Mind mapping video
- 又是被Visdom搞崩溃的一夜
猜你喜欢

聊聊高可用的 11 个关键技巧

初识CANOpen

Laravel excel export

High performance + million level Excel data import and export

Why are databases cloud native?

PPT绘图之AI助力论文图

Navicat premium view password scheme

QT TCP UDP network communication < theory >

使用Visio画立方体

Zhangxiaobai's road to penetration (7) -sql injection detailed operation steps -union joint query injection
随机推荐
Tp6 exception handling try catch writing method
英语口语 - 弱读
(3) Pyqt5 tutorial -- > signal and slot preliminary test
顺序表的折半查找法
Happy shopkeeper source code -- Introduction to happy shopkeeper system development mode
Summary of common MySQL database commands (from my own view)
Elemtnui select control combined with tree control to realize user-defined search method
Initialize the project using the express framework
Qt5 multi thread operation implemented by object base class and use of movetothread method
更新pip&下载jupyter lab
初识CANOpen
High performance + million level Excel data import and export
PHP parsing QR code content
Zhangxiaobai's road of penetration (IV) -- detailed explanation of XSS cross site script vulnerabilities
When MySQL queries fields in JSON format, it takes a property value of JSON data
2021-10-21
Huikan source code -- Huikan app system secondary development source code sharing
地理空间搜索 ->R树索引
yolov5训练使用的负样本图片
Go novice exploration road 1