china_city

省市区街道四级联选择 Rails Engine Gem

  • Owner: saberma/china_city
  • Platform:
  • License:: MIT License
  • Category::
  • Topic:
  • Like:
    0
      Compare:

Github stars Tracking Chart

ChinaCity 省市区街道级联选择

Build Status

china_city

简介

这是一个基于 Rails Engine 开发的插件,为 Rails 项目增加省市区街道四级(或者省市区三级、省市二级)选择框,可用于实现收货地址等信息的录入。

数据来源

安装

Gemfile

gem 'china_city'

app/assets/javascripts/application.js

//= require 'jquery'
//= require 'china_city/jquery.china_city'

config/routes.rb

mount ChinaCity::Engine => '/china_city'

使用

可以参考 https://github.com/saberma/china_city_example 示例代码。

在页面中加入选择框,示例代码使用 slim 格式

  .city-group
    select.city-select
      option --省份--
      = options_for_select(ChinaCity.list)
    select.city-select
      option --城市--
    select.city-select
      option --地区--
    select.city-select
      option --街道--

请留意:所有选择框都要有 city-select class,并都包含于 class='city-group' 的 DOM 元素之下。

选择后的值为国家地区编码,如深圳市的为 440300,可通过调用 ChinaCity.get('440300') 将编码转化为城市名称。

React 用户 react-china-city

如果你使用 React 和 webpack/browserify 可以直接使用 npm i react-china-city --save 来进行前端接入。

更新

  • 0.0.5 更新省市区数据到最新的国标,支持街道

贡献

git clone git@github.com:saberma/china_city.git
cd china_city
rake appraisal:install
cd spec/dummy
rails server
open http://localhost:3000/china_city

测试

brew install phantomjs    # http://git.io/vRJ1M
rvm use 2.1               # Fixed: NoMethodError: undefined method `using' for GB2260::Division:Class
rake appraisal:install
rake appraisal:rails4 spec

类似项目

Main metrics

Overview
Name With Ownersaberma/china_city
Primary LanguageRuby
Program languageRuby (Language Count: 5)
Platform
License:MIT License
所有者活动
Created At2013-08-13 13:52:55
Pushed At2016-09-23 08:45:02
Last Commit At2016-06-03 21:12:10
Release Count4
Last Release Namev0.0.4 (Posted on 2013-09-05 14:03:15)
First Release Namev0.0.1 (Posted on 2013-08-13 21:53:38)
用户参与
Stargazers Count355
Watchers Count14
Fork Count129
Commits Count95
Has Issues Enabled
Issues Count28
Issue Open Count8
Pull Requests Count10
Pull Requests Open Count5
Pull Requests Close Count5
项目设置
Has Wiki Enabled
Is Archived
Is Fork
Is Locked
Is Mirror
Is Private