Skip to content

Commit 41997f9

Browse files
committed
update 1.3.7
父元素增加 data-selects 属性设置 select 增加 data-query-name 属性设置
1 parent bb13778 commit 41997f9

File tree

3 files changed

+40
-14
lines changed

3 files changed

+40
-14
lines changed

README.md

Lines changed: 12 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -6,13 +6,14 @@ cxSelect 是基于 jQuery 的多级联动菜单插件,适用于省市、商品
66

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

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

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

13-
**版本:**
13+
**版本:**
14+
1415
* jQuery v1.7+
15-
* jQuery cxSelect v1.3.6
16+
* jQuery cxSelect v1.3.7
1617

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

@@ -130,6 +131,10 @@ $.cxSelect.defaults.nodata = 'none';
130131
<th>说明</th>
131132
</tr>
132133
</thead>
134+
<tr>
135+
<td>data-selects</td>
136+
<td>下拉选框组。输入 select 的 className,使用英文逗号分隔的字符串</td>
137+
</tr>
133138
<tr>
134139
<td>data-url</td>
135140
<td>列表数据接口地址(此处只能设置 URL,自定义需要在参数中设置)</td>
@@ -184,6 +189,10 @@ $.cxSelect.defaults.nodata = 'none';
184189
<td>data-url</td>
185190
<td>列表数据接口地址</td>
186191
</tr>
192+
<tr>
193+
<td>data-query-name</td>
194+
<td>传递上一个选框值得名称(默认使用上一个选框的 name 属性值)</td>
195+
</tr>
187196
<tr>
188197
<td>data-first-title</td>
189198
<td>选框第一个项目的标题</td>

js/jquery.cxselect.js

Lines changed: 25 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
11
/*!
22
* jQuery cxSelect
33
* @name jquery.cxselect.js
4-
* @version 1.3.6
5-
* @date 2015-11-03
4+
* @version 1.3.7
5+
* @date 2015-11-14
66
* @author ciaoca
77
* @email ciaoca@gmail.com
88
* @site https://github.com/ciaoca/cxSelect
@@ -64,6 +64,12 @@
6464
jsonSub: self.dom.box.data('jsonSub')
6565
});
6666

67+
var _dataSelects = self.dom.box.data('selects');
68+
69+
if (typeof _dataSelects === 'string' && _dataSelects.length) {
70+
self.settings.selects = _dataSelects.split(',');
71+
};
72+
6773
// 未设置选择器组
6874
if (!$.isArray(self.settings.selects) || !self.settings.selects.length) {return};
6975

@@ -157,7 +163,10 @@
157163
var _selectData;
158164
var _valueIndex;
159165
var _query = {};
166+
var _dataUrl = _select.data('url');
160167
var _jsonSpace = typeof _select.data('jsonSpace') === 'undefined' ? self.settings.jsonSpace : _select.data('jsonSpace');
168+
var _queryName;
169+
var _selectName;
161170

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

176-
if (typeof _select.data('url') === 'string' && _select.data('url').length) {
185+
if (typeof _dataUrl === 'string' && _dataUrl.length) {
177186
if (_indexPrev >= 0) {
178187
if (!self.selectArray[_indexPrev].val().length) {return};
179188

180-
_query[self.selectArray[_indexPrev].attr('name')] = self.selectArray[_indexPrev].val();
189+
_queryName = _select.data('queryName');
190+
_selectName = self.selectArray[_indexPrev].attr('name');
191+
192+
if (typeof _queryName === 'string' && _queryName.length) {
193+
_query[_queryName] = self.selectArray[_indexPrev].val();
194+
} else if (typeof _selectName === 'string' && _selectName.length) {
195+
_query[_selectName] = self.selectArray[_indexPrev].val();
196+
};
197+
181198
};
182199

183-
$.getJSON(_select.data('url'), _query, function(json) {
200+
$.getJSON(_dataUrl, _query, function(json) {
184201
_selectData = json;
185202

186203
if (typeof _jsonSpace === 'string' && _jsonSpace.length) {
@@ -265,11 +282,11 @@
265282
// 默认值
266283
$.cxSelect.defaults = {
267284
selects: [], // 下拉选框组
268-
url: null, // 列表数据文件路径,或设为对象
269-
nodata: null, // 无数据状态
285+
url: null, // 列表数据文件路径(URL)或数组数据
286+
nodata: null, // 无数据状态显示方式
270287
required: false, // 是否为必选
271288
firstTitle: '请选择', // 第一个选项选项的标题
272-
firstValue: '', // 第一个选项的值
289+
firstValue: '', // 第一个选项的值
273290
jsonSpace: '', // 数据命名空间
274291
jsonName: 'n', // 数据标题字段名称
275292
jsonValue: '', // 数据值字段名称

js/jquery.cxselect.min.js

Lines changed: 3 additions & 3 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)