首页 >web前端 >js教程 >Element UI级联选择器怎样获取级联对象

Element UI级联选择器怎样获取级联对象

php中世界最好的语言
php中世界最好的语言原创
2018-03-12 11:31:505114浏览

这次给大家带来Element UI级联选择器怎样获取级联对象,Element UI级联选择器获取级联对象的注意事项有哪些,下面就是实战案例,一起来看一下。

1.gif

代码:

getCascaderObj = function(val, opt){        return val.map(function (value, index, array) {            for (var itm of opt) {                if (itm.value == value) { opt = itm.children; return itm; }
            }            return null;
        });
    }

完整示例:

<!DOCTYPE html><html><head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <meta http-equiv="X-UA-Compatible" content="ie=edge">
    <title>Document</title>
    <link rel="stylesheet" href="https://unpkg.com/element-ui/lib/theme-default/index.css">
    <style>
    </style></head><body>
    <div id="app">
        <el-cascader v-model="val" placeholder="试试搜索:指南" :options="options" filterable @change="handleItemChange"></el-cascader>
        <div v-for="i in vals">
            label:{{i.label}} - value{{i.value}}        </div>
    </div>
    <script src="https://unpkg.com/vue/dist/vue.js"></script>
    <script src="https://unpkg.com/element-ui/lib/index.js"></script>
    <script> 
        function getCascaderObj(val,opt) {            return val.map(function (value, index, array) {                for (var itm of opt) {                    if (itm.value == value) { opt = itm.children; return itm; }
                }                return null;
            });
        }    </script>
    <script>
        var app = new Vue({
            el: &#39;#app&#39;,
            data: {
                vals:[],
                val: [],
                options: [{
                    value: &#39;zhinan&#39;,
                    label: &#39;指南&#39;,
                    children: [{
                        value: &#39;shejiyuanze&#39;,
                        label: &#39;设计原则&#39;,
                        children: [{
                            value: &#39;yizhi&#39;,
                            label: &#39;一致&#39;
                        }, {
                            value: &#39;fankui&#39;,
                            label: &#39;反馈&#39;
                        }, {
                            value: &#39;xiaolv&#39;,
                            label: &#39;效率&#39;
                        }, {
                            value: &#39;kekong&#39;,
                            label: &#39;可控&#39;
                        }]
                    }, {
                        value: &#39;daohang&#39;,
                        label: &#39;导航&#39;,
                        children: [{
                            value: &#39;cexiangdaohang&#39;,
                            label: &#39;侧向导航&#39;
                        }, {
                            value: &#39;dingbudaohang&#39;,
                            label: &#39;顶部导航&#39;
                        }]
                    }]
                }, {
                    value: &#39;zujian&#39;,
                    label: &#39;组件&#39;,
                    children: [{
                        value: &#39;basic&#39;,
                        label: &#39;Basic&#39;,
                        children: [{
                            value: &#39;layout&#39;,
                            label: &#39;Layout 布局&#39;
                        }, {
                            value: &#39;color&#39;,
                            label: &#39;Color 色彩&#39;
                        }, {
                            value: &#39;typography&#39;,
                            label: &#39;Typography 字体&#39;
                        }, {
                            value: &#39;icon&#39;,
                            label: &#39;Icon 图标&#39;
                        }, {
                            value: &#39;button&#39;,
                            label: &#39;Button 按钮&#39;
                        }]
                    }, {
                        value: &#39;form&#39;,
                        label: &#39;Form&#39;,
                        children: [{
                            value: &#39;radio&#39;,
                            label: &#39;Radio 单选框&#39;
                        }, {
                            value: &#39;checkbox&#39;,
                            label: &#39;Checkbox 多选框&#39;
                        }, {
                            value: &#39;input&#39;,
                            label: &#39;Input 输入框&#39;
                        }, {
                            value: &#39;input-number&#39;,
                            label: &#39;InputNumber 计数器&#39;
                        }, {
                            value: &#39;select&#39;,
                            label: &#39;Select 选择器&#39;
                        }, {
                            value: &#39;cascader&#39;,
                            label: &#39;Cascader 级联选择器&#39;
                        }, {
                            value: &#39;switch&#39;,
                            label: &#39;Switch 开关&#39;
                        }, {
                            value: &#39;slider&#39;,
                            label: &#39;Slider 滑块&#39;
                        }, {
                            value: &#39;time-picker&#39;,
                            label: &#39;TimePicker 时间选择器&#39;
                        }, {
                            value: &#39;date-picker&#39;,
                            label: &#39;DatePicker 日期选择器&#39;
                        }, {
                            value: &#39;datetime-picker&#39;,
                            label: &#39;DateTimePicker 日期时间选择器&#39;
                        }, {
                            value: &#39;upload&#39;,
                            label: &#39;Upload 上传&#39;
                        }, {
                            value: &#39;rate&#39;,
                            label: &#39;Rate 评分&#39;
                        }, {
                            value: &#39;form&#39;,
                            label: &#39;Form 表单&#39;
                        }]
                    }, {
                        value: &#39;data&#39;,
                        label: &#39;Data&#39;,
                        children: [{
                            value: &#39;table&#39;,
                            label: &#39;Table 表格&#39;
                        }, {
                            value: &#39;tag&#39;,
                            label: &#39;Tag 标签&#39;
                        }, {
                            value: &#39;progress&#39;,
                            label: &#39;Progress 进度条&#39;
                        }, {
                            value: &#39;tree&#39;,
                            label: &#39;Tree 树形控件&#39;
                        }, {
                            value: &#39;pagination&#39;,
                            label: &#39;Pagination 分页&#39;
                        }, {
                            value: &#39;badge&#39;,
                            label: &#39;Badge 标记&#39;
                        }]
                    }, {
                        value: &#39;notice&#39;,
                        label: &#39;Notice&#39;,
                        children: [{
                            value: &#39;alert&#39;,
                            label: &#39;Alert 警告&#39;
                        }, {
                            value: &#39;loading&#39;,
                            label: &#39;Loading 加载&#39;
                        }, {
                            value: &#39;message&#39;,
                            label: &#39;Message 消息提示&#39;
                        }, {
                            value: &#39;message-box&#39;,
                            label: &#39;MessageBox 弹框&#39;
                        }, {
                            value: &#39;notification&#39;,
                            label: &#39;Notification 通知&#39;
                        }]
                    }, {
                        value: &#39;navigation&#39;,
                        label: &#39;Navigation&#39;,
                        children: [{
                            value: &#39;menu&#39;,
                            label: &#39;NavMenu 导航菜单&#39;
                        }, {
                            value: &#39;tabs&#39;,
                            label: &#39;Tabs 标签页&#39;
                        }, {
                            value: &#39;breadcrumb&#39;,
                            label: &#39;Breadcrumb 面包屑&#39;
                        }, {
                            value: &#39;dropdown&#39;,
                            label: &#39;Dropdown 下拉菜单&#39;
                        }, {
                            value: &#39;steps&#39;,
                            label: &#39;Steps 步骤条&#39;
                        }]
                    }, {
                        value: &#39;others&#39;,
                        label: &#39;Others&#39;,
                        children: [{
                            value: &#39;dialog&#39;,
                            label: &#39;Dialog 对话框&#39;
                        }, {
                            value: &#39;tooltip&#39;,
                            label: &#39;Tooltip 文字提示&#39;
                        }, {
                            value: &#39;popover&#39;,
                            label: &#39;Popover 弹出框&#39;
                        }, {
                            value: &#39;card&#39;,
                            label: &#39;Card 卡片&#39;
                        }, {
                            value: &#39;carousel&#39;,
                            label: &#39;Carousel 走马灯&#39;
                        }, {
                            value: &#39;collapse&#39;,
                            label: &#39;Collapse 折叠面板&#39;
                        }]
                    }]
                }, {
                    value: &#39;ziyuan&#39;,
                    label: &#39;资源&#39;,
                    children: [{
                        value: &#39;axure&#39;,
                        label: &#39;Axure Components&#39;
                    }, {
                        value: &#39;sketch&#39;,
                        label: &#39;Sketch Templates&#39;
                    }, {
                        value: &#39;jiaohu&#39;,
                        label: &#39;组件交互文档&#39;
                    }]
                }]
            },
            methods: {
                handleItemChange() {                    this.vals=getCascaderObj(this.val, this.options);
                }
            }
        })    </script></body> </html>

相信看了本文案例你已经掌握了方法,更多精彩请关注php中文网其它相关文章!

相关阅读:

nodejs如何使用http模块编写上传图片接口测试客户端

python3如何通过qq邮箱发送邮件

以上是Element UI级联选择器怎样获取级联对象的详细内容。更多信息请关注PHP中文网其他相关文章!

声明:
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系admin@php.cn