From 0ec8e0b89ad7e91751f8f923749f44f9ca4a0aab Mon Sep 17 00:00:00 2001 From: thinkgem Date: Sun, 21 Jul 2024 17:44:35 +0800 Subject: [PATCH] add cascadeSelect js --- .../jquery-plugins/jquery.cascadeSelect.js | 91 +++++++++++++++++++ 1 file changed, 91 insertions(+) create mode 100644 common/src/main/resources/static/jquery-plugins/jquery.cascadeSelect.js diff --git a/common/src/main/resources/static/jquery-plugins/jquery.cascadeSelect.js b/common/src/main/resources/static/jquery-plugins/jquery.cascadeSelect.js new file mode 100644 index 00000000..ec2d0048 --- /dev/null +++ b/common/src/main/resources/static/jquery-plugins/jquery.cascadeSelect.js @@ -0,0 +1,91 @@ +/*! + * Copyright (c) 2013-Now http://jeesite.com All rights reserved. + * No deletion without permission, or be held responsible to law. + * 级联选择插件 + * @author ThinkGem + * @version 2021-4-25 + */ +(function ($) { + $.fn.cascadeSelect = function (options) { + var self = this, opts = $.extend({ + data: [], + id: "id", + name: "name", + children: "children", + blankOptionLabel: "请选择", + cssClass: 'form-control', + cssStyle: "width:150px", + change: function(){} + }, options); + var data = opts.data, + i, l, key = "id", parentKey = "pId", childKey = "children"; + if (Object.prototype.toString.apply(data) === "[object Array]") { + var treeData = [], map = []; + for (i=0, l=data.length; i").html("\n\ + .input-group.cascade-select .form-control {display:table-cell;}\n\ + .input-group.cascade-select .form-control:not(:last-child) {border-right:0}\n\ + .input-group.cascade-select .form-control:first-child:last-child {border-radius:4px}\n\ + ").appendTo($(self).addClass('cascade-select').parent()); + var html = '', data = opts.data, params = [data]; + html += ''; + $(self).html(html); + var createSelect = function() { + $(self).children('select').change(function () { + var self2 = this, val = $(self2).val().split("|")[1]; + $(self2).nextAll('select').remove(); + if (val % 1 == 0) { + var idx = $(self2).index(), html2 = ""; + params[idx + 1] = params[idx][val][opts.children];//一条线放一个数组 不同线重置 + html2 += ''; + $(self2).after(html2); + $(self).children("select").unbind("change"); + createSelect(); + } + var vals = [], names = []; + $(self).find('select').each(function(){ + var val = $(this).val(); + if (val != ''){ + vals.push(val.split("|")[0]); + names.push(unescape(val.split("|")[2])); + } + }); + opts.change(vals, names); + }) + } + createSelect(); + } +})(jQuery); \ No newline at end of file