[英]How to change the selected text value in jquery multiselect
This is my multiselect code.. 这是我的多选代码。
$("#cboMethod").multiselect({
header: true,
height: 150,
selectedText: '# Method Selected',
selectedList: 2,
noneSelectedText: "Select Method",
minWidth: 210
});
In my case i have three or more options... Let it be 'OptionA','OptionB','OptionC' etc.. So i need my selectedText to shown as 'OptionA' if i select 'OptionA' alone. 在我的情况下,我有三个或更多选项...设为“ OptionA”,“ OptionB”,“ OptionC”等。因此,如果我单独选择“ OptionA”,则需要我的selectedText显示为“ OptionA”。 And it should be 'OptionA,...' if i selected more values including 'OptionA' 如果我选择了包括“ OptionA”在内的更多值,则应为“ OptionA,...”
I used selectedList: 2,
so if i select only 'OptionA' its working as expected... but if select more options it is getting changed to ' OptionA,OptionB'... 我使用了selectedList: 2,
所以如果我仅选择“ OptionA”,其将按预期工作...但是如果选择更多选项,它将变为“ OptionA,OptionB” ...
Is that possible to make it as ' OptionA,...
' 是否可以将其设置为“ OptionA,...
”
I have got my solution by doing a small change in multiselect.js 我通过在multiselect.js中进行小的更改获得了解决方案
This is the code change: 这是代码更改:
Original code: 原始代码:
else if (/\d/.test(o.selectedList) && o.selectedList > 0 && numChecked <= o.selectedList) {
value = $checked.map(function () { return $(this).next().text(); }).get().join(', ');
}
Changed Code: 更改的代码:
else if (/\d/.test(o.selectedList) && o.selectedList > 0 && numChecked <= o.selectedList) {
var result = $checked.map(function () { return $(this).next().text(); }).get().join(', ');
result = result.split(',');
if (result.length > 1) {
value = result[0] + ',...';
}
else {
value = $checked.map(function () { return $(this).next().text(); }).get().join(', ');
}
}
This gave me the solution..:) 这给了我解决方案.. :)
Try this: 尝试这个:
$.map($(this).multiselect("getChecked"), function( input ){
return input.value;
});
to show the selected text what you can do is you can make a check on the length of the selected like shown below: 要显示所选文本,您可以做的就是检查所选内容的长度,如下所示:
checkedValues.length > 0 ? checkedValues.length > 1 ? checkedValues[0] + ',...' : checkedValues[0] : 'Please select an input'
Simply do: 只需做:
$('#example-reset').multiselect({
header: true,
height: 150,
allSelectedText: 'ALL UNITS SELECTED',
selectedList: 1,
numberDisplayed: 1,
nonSelectedText: "CLICK TO SELECT",
minWidth: 210
});
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.