npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

lc-city-selector

v1.1.4

Published

city-selector

Downloads

16

Readme

省-市-区三级联动城市选择器


效果

演示地址:https://licong96.github.io/work/lc-city-selector/index.html

效果

无依赖

纯js手写,使用简单,不依赖任何插件

安装

npm安装或者cnpm:

    npm install lc-city-selector --save

yarn安装:

    yarn add lc-city-selector
    

使用

    import LcCity from 'lc-city-selector';

    var City = new LcCity();    // 创建实例化对象
    City.show();    // 执行show方法

confirm

回调函数,可以在里面拿到选中的地区

    import LcCity from 'lc-city-selector';
    var City = new LcCity({
        confirm: function (data) {
            console.log(data);  // data就是选中的地区,一个拼接好的字符串
        }
    });
    
    ----------
    如果你不想用回调的方式
    可以用`City.getSelect()`方法直接获取当前选中的地区

数据回填

如果你已经有了数据,想要回填进去,可以加一个data参数,但是要注意它的格式

    import LcCity from 'lc-city-selector';
    var City = new LcCity({
        data: {
            province: '江西省',
            city    : '南昌市',
            district: '青山湖区',
        }
    });
    
    注意:键要相同,值要完整,省、市、区这几个字不要省略

参数

| 参数 | 类型 | 说明 | 默认值 | | :--------: | :-----: | :----: | :----: | | data | Object | 需要回填的数据 | 空 | | confirm | Function | 触发确定按钮,返回选中的地区 | 空 | | cancel | Function | 触发取消按钮,没有返回值 | 空 |

API

  1. show(),打开选择器
  2. close(),关闭选择器
  3. getSelect(),获取当前选中的区域,已拼接成了一个字符串
  4. getSelectObj(),获取当前选中的区域,返回的是一个对象

电脑端需要注意

虽然样式上已经做了兼容,但是选择器的位置有偏移,所以在电脑上打开需要传入一个元素,我会把元素距离屏幕的位置,赋值给选择器,让选择器和元素凑在一起

    import LcCity from 'lc-city-selector';

    var City = new LcCity();    // 创建实例化对象
    
    // 假设有一个id为input的元素,点击它来打开选择器
    
    var oInput =  document.getElementById('input');
    
    oInput.addEventListener('click', function() {
      City.show(this);  // 这里的this指向的是oInput
    });
    

欢迎提出建议和问题,我会第一时间处理