Skip to content

Commit bb13778

Browse files
committed
update 1.3.6
支持简单数组数据
1 parent 1e3344d commit bb13778

File tree

3 files changed

+27
-19
lines changed

3 files changed

+27
-19
lines changed

README.md

+5-3
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ cxSelect 是基于 jQuery 的多级联动菜单插件,适用于省市、商品
1212

1313
**版本:**
1414
* jQuery v1.7+
15-
* jQuery cxSelect v1.3.5
15+
* jQuery cxSelect v1.3.6
1616

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

@@ -206,5 +206,7 @@ $.cxSelect.defaults.nodata = 'none';
206206
</tr>
207207
</table>
208208

209-
##自定义数据
210-
详见 [DEMO](http://code.ciaoca.com/jquery/cxselect/demo/custom.html)
209+
##示例
210+
自定义数据及使用纯数组数据 [DEMO](http://code.ciaoca.com/jquery/cxselect/demo/custom.html)
211+
212+
各选项数据接口独立 [DEMO](http://code.ciaoca.com/jquery/cxselect/demo/oneself.html)

js/jquery.cxselect.js

+19-13
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.5
5-
* @date 2015-10-30
4+
* @version 1.3.6
5+
* @date 2015-11-03
66
* @author ciaoca
77
* @email ciaoca@gmail.com
88
* @site https://github.com/ciaoca/cxSelect
@@ -222,21 +222,27 @@
222222
var _jsonName = typeof select.data('jsonName') === 'undefined' ? self.settings.jsonName : String(select.data('jsonName'));
223223
var _jsonValue = typeof select.data('jsonValue') === 'undefined' ? self.settings.jsonValue : String(select.data('jsonValue'));
224224

225-
// 至少设置标题字段
226-
if (!_jsonName.length) {return};
227-
228-
// 无值字段时使用标题作为值
229-
if (!_jsonValue.length) {
230-
_jsonValue = _jsonName;
231-
};
232-
233225
if (!$.isArray(data)) {return};
234226

235227
var _html = !self.settings.required ? '<option value="' + _firstValue + '">' + _firstTitle + '</option>' : '';
236228

237-
$.each(data, function(i, v) {
238-
_html += '<option value="' + String(v[_jsonValue]) + '">' + String(v[_jsonName]) + '</option>'
239-
});
229+
// 区分标题或值的数据
230+
if (_jsonName.length) {
231+
// 无值字段时使用标题作为值
232+
if (!_jsonValue.length) {
233+
_jsonValue = _jsonName;
234+
};
235+
236+
for (var i = 0, l = data.length; i < l; i++) {
237+
_html += '<option value="' + String(data[i][_jsonValue]) + '">' + String(data[i][_jsonName]) + '</option>';
238+
};
239+
240+
// 数组即为值的数据
241+
} else {
242+
for (var i = 0, l = data.length; i < l; i++) {
243+
_html += '<option value="' + String(data[i]) + '">' + String(data[i]) + '</option>';
244+
};
245+
};
240246

241247
select.html(_html).prop('disabled', false).css({
242248
'display': '',

js/jquery.cxselect.min.js

+3-3
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)