Home > Web Front-end > JS Tutorial > body text

How to implement Infinity Selector based on layui (with code)

不言
Release: 2018-08-25 15:49:35
Original
3240 people have browsed it

The content of this article is about how to implement the Infinity Selector (with code) based on layui. It has certain reference value. Friends in need can refer to it. I hope it will be helpful to you.

html element

<div class="layui-form-item">
    <label class="layui-form-label">选择框</label>
    <div class="layui-input-block">
        <input type="text" id="a" class="layui-input" readonly="readonly">
    </div>
</div>
Copy after login

js reference

layui.use([&#39;form&#39;,"jquery","cascader"], function(){
    var $ = layui.jquery;
    var cascader = layui.cascader;
    
    var data = [
        {
            value: &#39;A&#39;,
            label: &#39;a&#39;,
            children: [
                {
                    value: &#39;AA1&#39;,
                    label: &#39;aa1&#39;,
                },
                {
                    value: &#39;BB1&#39;,
                    label: &#39;bb1&#39;
                }
            ]
        },
        {
            value: &#39;B&#39;,
            label: &#39;b&#39;,
        }
    ]
    cascader({
        elem: "#a",
        data: data,
        // url: "/aa",
        // type: "post",
        // triggerType: "change",
        // showLastLevels: true,
        // where: {
        //     a: "aaa"
        // },
        value: ["A", "AA1"],
        success: function (data) {
            console.log(data);
        }
    });
});
Copy after login

cascader parameter description

1. elem: input container
2. data: required static data , type is array,
3. url: data obtained asynchronously, type is array, (choose one of the two parameters data and url)
4. type: asynchronous acquisition method, default get, can be omitted
5. where: asynchronously passed in parameters, can be omitted
6. triggerType: trigger mode, leave it blank or all others are click, optional parameter "change", which is triggered when the mouse moves in
7, showLastLevels : Whether the input box only displays the last level, the default is false, that is, all display
8, value: the initial value passed in, the type is an array, the value is the value of data
9, success: callback function, select The callback function after completion returns the value array

Online demo
github source code

Related recommendations :

Detailed analysis of layui’s project optimization and non-intrusive optimization

Conflict resolution between dynamic rendering of layui form and vue.js ( Code attached)

The above is the detailed content of How to implement Infinity Selector based on layui (with code). For more information, please follow other related articles on the PHP Chinese website!

Related labels:
source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template
About us Disclaimer Sitemap
php.cn:Public welfare online PHP training,Help PHP learners grow quickly!