GithubHelp home page GithubHelp logo

justice996 / picker Goto Github PK

View Code? Open in Web Editor NEW

This project forked from xingchou/picker

0.0 1.0 0.0 72 KB

移动端的联动选择器组件

Home Page: https://xingchou.github.io/pluginApp/dist/index.html#/list/picker

JavaScript 98.06% HTML 1.37% CSS 0.56%

picker's Introduction

Picker

移动端的联动选择器组件(例如:地址省市区三级联动),压缩后只有几KB,非常小巧

Usage

import:
    import Picker from 'picker.min.js'
    @import "picker.css"
    
直接引入:
    <link href="picker.css" rel="stylesheet" />
    <script src='picker.min.js'></script>

Data

// 例:城市数据(3级联动)
let cityData = {
    "Code": "310000",
    "Name": "上海市",
    "level": [
        {
            "Code": "310000",
            "Name": "上海市",
            "sort": 1,
            "level": [
                {
                    "Code": "312000",
                    "Name": "黄浦区",
                    "sort": 1
                }
            ]
        }
    ]
}

Function

// 选择器(将方法封装到函数内,每次使用调用此函数就行)
new Picker({
    "title": '请选择', //标题(可选)
    
    //默认值: 多个用空格隔开;(可选)
    "defaultValue": '上海市 上海市 上海市', 

    //需要联动级数[1、2、3](可选)
    //不传时默认获取数据的深度,最多3级
    "type": 1,

    //数据(必选)
    //在使用时,把cityData替换为后台返回的数据即可,但格式要和cityData一致
    "data": cityData, 

    //数据内的键名称[Code、Name、level](必选)
    "keys": {
        "id": "Code",
        "value": "Name",
        "childData": "level"
    },

   //回调函数(val为当前选中的值)(必选)
   "callBack": function (val) {
     
        // 可在此处显示选中的值
    }
});

Demo:

https://xingchou.github.io/pluginApp/dist/index.html#/list/picker

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.