Skip to content

Commit

Permalink
update 1.3.7
Browse files Browse the repository at this point in the history
父元素增加 data-selects 属性设置
select 增加 data-query-name 属性设置
  • Loading branch information
ciaoca committed Nov 14, 2015
1 parent bb13778 commit 41997f9
Show file tree
Hide file tree
Showing 3 changed files with 40 additions and 14 deletions.
15 changes: 12 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,13 +6,14 @@ cxSelect 是基于 jQuery 的多级联动菜单插件,适用于省市、商品

同时兼容 Zepto,方便在移动端使用。

国内省市县数据来源:<a href="https://github.com/basecss/cityData" target="_blank">basecss/cityData</a> Date: 2014.03.31
国内省市县数据来源:[basecss/cityData](https://github.com/basecss/cityData) Date: 2014.03.31

全球主要城市数据来源:整理国内常用网站和软件 Date: 2014.07.29

**版本:**
**版本:**

* jQuery v1.7+
* jQuery cxSelect v1.3.6
* jQuery cxSelect v1.3.7

文档:http://code.ciaoca.com/jquery/cxselect/

Expand Down Expand Up @@ -130,6 +131,10 @@ $.cxSelect.defaults.nodata = 'none';
<th>说明</th>
</tr>
</thead>
<tr>
<td>data-selects</td>
<td>下拉选框组。输入 select 的 className,使用英文逗号分隔的字符串</td>
</tr>
<tr>
<td>data-url</td>
<td>列表数据接口地址(此处只能设置 URL,自定义需要在参数中设置)</td>
Expand Down Expand Up @@ -184,6 +189,10 @@ $.cxSelect.defaults.nodata = 'none';
<td>data-url</td>
<td>列表数据接口地址</td>
</tr>
<tr>
<td>data-query-name</td>
<td>传递上一个选框值得名称(默认使用上一个选框的 name 属性值)</td>
</tr>
<tr>
<td>data-first-title</td>
<td>选框第一个项目的标题</td>
Expand Down
33 changes: 25 additions & 8 deletions js/jquery.cxselect.js
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
/*!
* jQuery cxSelect
* @name jquery.cxselect.js
* @version 1.3.6
* @date 2015-11-03
* @version 1.3.7
* @date 2015-11-14
* @author ciaoca
* @email [email protected]
* @site https://github.com/ciaoca/cxSelect
Expand Down Expand Up @@ -64,6 +64,12 @@
jsonSub: self.dom.box.data('jsonSub')
});

var _dataSelects = self.dom.box.data('selects');

if (typeof _dataSelects === 'string' && _dataSelects.length) {
self.settings.selects = _dataSelects.split(',');
};

// 未设置选择器组
if (!$.isArray(self.settings.selects) || !self.settings.selects.length) {return};

Expand Down Expand Up @@ -157,7 +163,10 @@
var _selectData;
var _valueIndex;
var _query = {};
var _dataUrl = _select.data('url');
var _jsonSpace = typeof _select.data('jsonSpace') === 'undefined' ? self.settings.jsonSpace : _select.data('jsonSpace');
var _queryName;
var _selectName;

// 清空后面的 select
for (var i = 0, l = self.selectArray.length; i < l; i++) {
Expand All @@ -173,14 +182,22 @@
};
};

if (typeof _select.data('url') === 'string' && _select.data('url').length) {
if (typeof _dataUrl === 'string' && _dataUrl.length) {
if (_indexPrev >= 0) {
if (!self.selectArray[_indexPrev].val().length) {return};

_query[self.selectArray[_indexPrev].attr('name')] = self.selectArray[_indexPrev].val();
_queryName = _select.data('queryName');
_selectName = self.selectArray[_indexPrev].attr('name');

if (typeof _queryName === 'string' && _queryName.length) {
_query[_queryName] = self.selectArray[_indexPrev].val();
} else if (typeof _selectName === 'string' && _selectName.length) {
_query[_selectName] = self.selectArray[_indexPrev].val();
};

};

$.getJSON(_select.data('url'), _query, function(json) {
$.getJSON(_dataUrl, _query, function(json) {
_selectData = json;

if (typeof _jsonSpace === 'string' && _jsonSpace.length) {
Expand Down Expand Up @@ -265,11 +282,11 @@
// 默认值
$.cxSelect.defaults = {
selects: [], // 下拉选框组
url: null, // 列表数据文件路径,或设为对象
nodata: null, // 无数据状态
url: null, // 列表数据文件路径(URL)或数组数据
nodata: null, // 无数据状态显示方式
required: false, // 是否为必选
firstTitle: '请选择', // 第一个选项选项的标题
firstValue: '', // 第一个选项的值
firstValue: '', // 第一个选项的值
jsonSpace: '', // 数据命名空间
jsonName: 'n', // 数据标题字段名称
jsonValue: '', // 数据值字段名称
Expand Down
6 changes: 3 additions & 3 deletions js/jquery.cxselect.min.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

0 comments on commit 41997f9

Please sign in to comment.