hnzzmsf / layui-formselects Goto Github PK
View Code? Open in Web Editor NEWLayui select多选小插件
Home Page: https://gitee.com/maplemei/xm-select
License: Apache License 2.0
Layui select多选小插件
Home Page: https://gitee.com/maplemei/xm-select
License: Apache License 2.0
多选框 回显老是有问题啊 概率性 时而回显时而不回显。数据回显概率性出现问题,测试的同一个数据,一会儿显示,一会儿不显示。
'''javascript
ajax = {
type: 'get',
header: {
},
first: true,
data: {},
searchUrl: '',
searchName: 'keyword',
searchVal: null,
keyName: 'name', //能否以参数形式,自定义该字段名称
keyVal: 'value', //能否以参数形式,自定义该字段名称
keySel: 'selected',
keyDis: 'disabled',
keyChildren: 'children', //能否以参数形式,自定义该字段名称
dataType: '',
delay: 500,
beforeSuccess: null,
success: null,
error: null,
beforeSearch: null,
response: {
statusCode: 0,
statusName: 'code',
msgName: 'msg',
dataName: 'data'
},
tree: {
nextClick: function(id, item, callback) {
callback([]);
},
folderChoose: true,
lazy: true
}
},
'''
如果下拉款不是很长,选择多个选项,xm-select-title高度会自动撑开,但是在 layui Tab下来回切换后,.xm-select-title高度变为0,如果点击一下下拉按钮才会恢复
github上文档和你个人网址上的不一致
github文档里 on 方法里面还是写的 val,应该是value
(这个改动造成不兼容,文档一定要清楚呀)
搜索后的结果,点击全选,会全选所有选项,包括不在搜索结果里的选项。
比如数据有1 、11、 111、 2、 3
搜索:1,结果为1、11、111
点击全选后,选中的为:1 、11、 111、 2、 3。
把不在搜索范围内容的选项也选中了
Common.prototype.create = function(id, isCreate, inputValue){
if(isCreate && inputValue){
let fs = data[id],
dl = $([xid="${id}"]
),
tips= dl.find(dd.${FORM_SELECT_TIPS}.${FORM_DL_INPUT}
),
tdd = null,
temp = dl.find(dd.${TEMP}
);
dl.find(dd:not(.${FORM_SELECT_TIPS}):not(.${TEMP})
).each((index, item) => {
if(inputValue == $(item).find('span').attr('name')){
tdd = item;
}
});
if(!tdd){//如果不存在, 则创建
//let val = fs.config.create(id, name);
let val = fs.config.create(id, inputValue); //这里是不是要把inputValue传过去
if(temp[0]){
temp.attr('lay-value', val);
temp.find('span').text(inputValue);
temp.find('span').attr("name", val); //这里是不是要加上这一行
temp.removeClass(DD_HIDE);
}else{
tips.after($(this.createDD(id, {
innerHTML: inputValue,
value: val
}, ${TEMP} ${CREATE_LONG}
)));
}
}
}else{
$([xid=${id}] dd.${TEMP}
).remove();
}
}
注释的两行
怎样将数据填充到循环列表中
多级联动 本地数据 初始赋值 按照文档上的写的 formSelects.value('select_person', ["999/1/12"]); 但是还是显示不出来默认值 后来试了一下您的文档的代码 写了一个DEMO 也还是显示不出来 还请您看下这个问题呢 是我的代码哪里写错了还是怎么的
导致layui的select点击事件没反应没反应,(用的是v4版的)
<form id="queryForm" class="layui-form" >
<div class="layui-form-item">
<div class="layui-inline">
<label class="layui-form-label">选择性别</label>
<div class="layui-input-inline" style="width:80px">
<select id="selectSex">
<option value="1">男</option>
<option value="2">女</option>
</select>
</div>
</div>
<div class="layui-inline">
<label class="layui-form-label">选择班级</label>
<div class="layui-input-inline" style="width:300px">
<select name="clazz" xm-select="clazz" xm-select-search="#(WEB_HOST)/admin/matchDormitory/searchClazz"></select>
</div>
</div>
<div class="layui-inline">
<label class="layui-form-label">选择人员</label>
<div class="layui-input-inline" style="width:300px">
<select name="person" xm-select="person" xm-select-search="#(WEB_HOST)/admin/matchDormitory/searchPerson"></select>
</div>
</div>
</div>
</form>
{
"value": 7,
"name": "事业部二",
"disabled": "disabled",
"children": [
{
"value": 10,
"name": "事业部2.1",
"selected": "selected",
"children": [
{
"value": 11,
"name": "事业部2.1.1",
"selected": "selected",
"children": []
}
]
}
]
}
]
},
json数据父节点设置了disabled,子节点对应的也给禁用了,有没有操作,可以父节点禁用,不影响子节点的选择
怎麼自定義value的指,默認的Date.now()不好用。
搜索时候如何忽略大小写
formSelects.config('parentMenu_select', {
// 转换数据格式
beforeSuccess: function(id, url, searchVal, result){
//我要把数据外层的code, msg, data去掉
result = result.data;
//我要反转name
covertData(result);
//然后返回数据
return result;
}
}).data('parentMenu_select', 'server', {
url: setter.requestUrl+'menu/menuTree?token='+layui.data(setter.tableName)[setter.request.tokenName],
response: {
statusCode: 200,
}
});
以官方代码片段为例。这段代码打开一个弹窗,提交表单。
layer.open({
type: 2
,title: '编辑用户'
,content: '../../../views/user/user/userform.html'
,maxmin: true
,area: ['500px', '450px']
,btn: ['确定', '取消']
,yes: function(index, layero){
var iframeWindow = window['layui-layer-iframe'+ index]
,submitID = 'LAY-user-front-submit'
,submit = layero.find('iframe').contents().find('#'+ submitID);
//监听提交
iframeWindow.layui.form.on('submit('+ submitID +')', function(data){
var field = data.field; //获取提交的字段
//提交 Ajax 成功后,静态更新表格中的数据
//$.ajax({});
table.reload('LAY-user-front-submit'); //数据刷新
layer.close(index); //关闭弹层
});
submit.trigger('click');
}
,success: function(layero, index){
}
});
加入 formSelects 后导致无法提交表单。
原因:use formSelects 之后,formSelects初始化会绑定一些事件,代码678行
Common.prototype.one 函数,首先将 document 的事件全部 off('click') ,然后再绑定 formSelects 相关的事件。这个过程把表单提交按钮的事件移除了,所以无法trigger('click') 。
我没有仔细阅读代码。简单把 off('click') 加上选择器,解决这个问题,不知道是不是破坏了一些功能。
具体修改如下:
//一次性事件绑定
- $(target ? target : document).off('click').on('click', '.' + FORM_TITLE, function (e) {
+ $(target ? target : document).off('click', '.' + FORM_TITLE).on('click', '.' + FORM_TITLE, function (e) {
`
var active = {
addInput: function () {
var index = jq('#enumDiv select').length;
var newInput = ' <div class="layui-inline">\n' +
' <label class="layui-form-label"></label>\n' +
' <div class="layui-input-inline" style="width: 10%;">\n' +
' <input type="text" name="enumName" placeholder="名称" autocomplete="off" class="layui-input">\n' +
' </div>\n' +
' <div class="layui-input-inline" style="width: 15%;">\n' +
' <input type="text" name="enumValue" placeholder="枚举值" autocomplete="off" class="layui-input">\n' +
' </div>\n' +
' <div class="layui-input-inline" style="width: 40%;">\n' +
' <select name="enumCity" xm-select="selectEnumCity' + index + '"id="selectEnumCity' + index + '" xm-select-show-count="3"\n' +
' xm-select-search="" xm-select-search-type="dl">\n' +
' </select>\n' +
' </div>\n' +
' <div class="layui-input-inline" style="width: 10%">\n' +
' <input type="text" name="enumSort" placeholder="排序" autocomplete="off" class="layui-input">\n' +
' </div>\n' +
' <div class="layui-input-inline" style="width: 5%">\n' +
' <input type="button" value="删除" data-method="delInput" class="layui-btn layui-btn-danger">\n' +
' </div>\n' +
' </div>';
jq('#enumDiv').append(newInput);
//formSelects.init(newInput)
formSelects.render();
//formSelects.config('selectEnumCity' + index, {}, false);
//formSelects.btns('selectEnumCity' + index, ['remove']);
//formSelects.value('selectEnumCity' + index,[1]);
//formSelects.render('selectEnumCity' + index);
},
delInput: function (othis) {
othis.parents('.layui-inline').remove();
}
};
//动态增加、删除枚举框
jq('#enumDiv').on('click', '.layui-btn', function () {
var othis = jq(this), method = othis.data('method');
active[method].call(this, othis);
});`
当我进行button动态增加多选框的,时候formSelect事件都失效了,请问该如何解决呢?
使用版本:4.0.0.0713
1、(设定在中文输入法) 第一次开始输入拼音首字母时时会触发一次搜索, 而并没有等到设定的延迟时间之后.
使用的是文档页面提供的 空内容不搜索beforeSearch
方法,第一次之后再输入拼音都是等到延迟之后的
2、远程搜索 当搜索框的位置设置为dl
时, 完成搜索后搜索内容自动清空, 此时还未选择
3、远程搜索完后如何定制模板?
当的动态绑定数据较多数时,点击某些选项右侧空白处,如点击 [分组-1] 的 [上海] 的右侧空白处,会出现树状结构支持收缩图标,而且某些分组选项随之不见了
直接在官方demo上叠加数据就可以重现
formSelects.data('example6_1', 'local', {
arr: [
{"name": "分组-1", "type": "optgroup"},
{"name": "北京", "value": 1},
{"name": "上海", "value": 2},
{"name": "分组-2", "type": "optgroup"},
{"name": "广州", "value": 3},
{"name": "深圳", "value": 4},
{"name": "天津", "value": 5},
{"name": "分组-3", "type": "optgroup"},
{"name": "广州3", "value": 6},
{"name": "深圳3", "value": 7},
{"name": "天津3", "value": 8},
{"name": "分组-4", "type": "optgroup"},
{"name": "广州4", "value": 9},
{"name": "深圳4", "value": 10},
{"name": "天津4", "value": 11},
{"name": "分组-5", "type": "optgroup"},
{"name": "广州5", "value": 12},
{"name": "深圳5", "value": 13},
{"name": "天津5", "value": 14},
{"name": "分组-6", "type": "optgroup"},
{"name": "广州6", "value": 15},
{"name": "深圳6", "value": 16},
{"name": "天津6", "value": 17},
{"name": "分组-7", "type": "optgroup"},
{"name": "广州7", "value": 18},
{"name": "深圳7", "value": 19},
{"name": "天津7", "value": 20},
{"name": "分组-8", "type": "optgroup"},
{"name": "广州8", "value": 21},
{"name": "深圳8", "value": 22},
{"name": "天津8", "value": 23}
]
});
当select选项值过多时,会出现一些卡顿情况。这一问题,一般主要出现在远程获取数据这种场景,所以,建议作者在远程下拉这一功能时,多做一个分页功能。分多次去请求数据。
原:li = dl.find('.xm-select-linkage-group' + index + ':not(.xm-select-linkage-hide) li[value="' + pid + '"]');
修复为:li = dl.find('.xm-select-linkage-group' + index + ':not(.xm-select-linkage-hide) li[xm-value="' + pid + '"]');
使用远程数据,无法设置默认值
formSelects.value('select1', ['110000/110100/110101'])
原:var span = '<li title="' + item.name + '"
修改为: var span = '<li class="xm-select-li" title="' + item.name + '"
原:othis = othis.is('li') ? othis : othis.parents('li');
修改为:othis = othis.is('li') ? othis : othis.parents('li.xm-select-li');
Common.prototype.linkageDel = function(id, val){ let dl = $(
dl[xid="${id}"]); let vs = val.value.split('/'); let pid, li, index = vs.length - 1; do{ pid = vs[index]; li = dl.find(
.xm-select-linkage-group${index + 1} li[xm-value="${pid}"]); if(!li.parent().next().find(
li[pid=${pid}].xm-select-this).length){ li.removeClass('xm-select-this'); } index --; }while(li.length && pid != undefined); }
这里应该是 li[pid="${pid}"],
或者是将pid= vs[index]改为pid= vs[index-1]
个人微信号:cuimoman
望探讨
layui 最新版 v2.4.3 无法使用
方便上传一下编译的工具吗?因为业务上的原因,需要修改下源码,但是直接修改编译后的代码,感觉不太好。
多谢 🙏
正常情况下Layui默认的select是兼容Vue的,但只要我加上xm-select="select1" 就会报错,能不能请修复一下, 任何js插件,兼容vue相信是很多人都希望的
请求支持懒加载子集数据,就是点父级的时候才加载子集数据,
因为如果树太庞大的话,一次加载整个树,数据量太大,时间很长,数据量也很大,有问题
有时候由于请求异步的问题,导致在formSelects.value('id',[xxxx])时,数据还没有初始化好
这边的项目select多选,select的条目比较多,多达5000个,点击下拉框时好一会才出来,请问这个有啥办法优化吗
formSelects.data('select_1', 'server', {
url : './../url'
});
再设置btns显示模式,无效,不管设置什么都显示的是图标+名称
1.树形结构是默认展开的,无法改为默认关闭
2.树形结构,父节点若disabled=true ,则子节点也会自动设置为disabled=true,且无法修改。
3.父节点前的选择框无法去掉
4.只能通过ID渲染,无法通过其他选择器渲染
c#下使用,现在的字符串拼接传值的方式会导致页面验证失败,最好能够提供支持原生的select数组回传的方式,这样就可以用c#的回发了!
有没有动态增加删除option的方法
当选项值过多的时候全选会很卡,两千多个值的时候,全选和取消都会卡住
1.能否兼容layui的form.val()方法进行赋值
2.树视图能否加上连接线可选项
3.建议加上reload刷新数据的方法,进行动态本地或者远程数据加载
A declarative, efficient, and flexible JavaScript library for building user interfaces.
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google ❤️ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.