Skip to content

Commit

Permalink
update 1.3.6
Browse files Browse the repository at this point in the history
支持简单数组数据
  • Loading branch information
ciaoca committed Nov 7, 2015
1 parent 1e3344d commit bb13778
Show file tree
Hide file tree
Showing 3 changed files with 27 additions and 19 deletions.
8 changes: 5 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ cxSelect 是基于 jQuery 的多级联动菜单插件,适用于省市、商品

**版本:**
* jQuery v1.7+
* jQuery cxSelect v1.3.5
* jQuery cxSelect v1.3.6

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

Expand Down Expand Up @@ -206,5 +206,7 @@ $.cxSelect.defaults.nodata = 'none';
</tr>
</table>

##自定义数据
详见 [DEMO](http://code.ciaoca.com/jquery/cxselect/demo/custom.html)
##示例
自定义数据及使用纯数组数据 [DEMO](http://code.ciaoca.com/jquery/cxselect/demo/custom.html)

各选项数据接口独立 [DEMO](http://code.ciaoca.com/jquery/cxselect/demo/oneself.html)
32 changes: 19 additions & 13 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.5
* @date 2015-10-30
* @version 1.3.6
* @date 2015-11-03
* @author ciaoca
* @email [email protected]
* @site https://github.com/ciaoca/cxSelect
Expand Down Expand Up @@ -222,21 +222,27 @@
var _jsonName = typeof select.data('jsonName') === 'undefined' ? self.settings.jsonName : String(select.data('jsonName'));
var _jsonValue = typeof select.data('jsonValue') === 'undefined' ? self.settings.jsonValue : String(select.data('jsonValue'));

// 至少设置标题字段
if (!_jsonName.length) {return};

// 无值字段时使用标题作为值
if (!_jsonValue.length) {
_jsonValue = _jsonName;
};

if (!$.isArray(data)) {return};

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

$.each(data, function(i, v) {
_html += '<option value="' + String(v[_jsonValue]) + '">' + String(v[_jsonName]) + '</option>'
});
// 区分标题或值的数据
if (_jsonName.length) {
// 无值字段时使用标题作为值
if (!_jsonValue.length) {
_jsonValue = _jsonName;
};

for (var i = 0, l = data.length; i < l; i++) {
_html += '<option value="' + String(data[i][_jsonValue]) + '">' + String(data[i][_jsonName]) + '</option>';
};

// 数组即为值的数据
} else {
for (var i = 0, l = data.length; i < l; i++) {
_html += '<option value="' + String(data[i]) + '">' + String(data[i]) + '</option>';
};
};

select.html(_html).prop('disabled', false).css({
'display': '',
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 bb13778

Please sign in to comment.