我用过select2输入下拉菜单并与值文本对绑定(bind),它会根据(租户名称)文本正确进行过滤,如下所示。
<li class="dropdown" id="liTenancy" style="margin-top: 4px; min-width: 250px !important;">
<select class="form-control select2me" data-placeholder="Select..." style="white-space: nowrap;">
@foreach (var Tenancy in Entity)
{
<option @(SelectedTenancy == Tenancy.TenancyId ? "selected=\"selected\"" : "") value="@Tenancy.TenancyId">
<a class="optionTenancy" href="javascript:void(0);" id="@Tenancy.TenancyId">@Tenancy.TenancyName</a>
</option>
}
</select>
</li>
现在我想用tenancyname(文本)或tenancyid(值)过滤这个列表(用户可以使用这两个过滤列表)那么我如何自定义js而不使用远程调用呢? ?
最佳答案
感谢 kevin 的建议,我找到了如下的解决方案,这对任何其他用户都有帮助
我已将 id 放入 value 属性中,将 guid 放入选项标记的 alt 属性中,并使用自定义匹配器,如下所示
$('select.select2me').select2({
placeholder: "Select",
allowClear: true,
matcher: function (term, text, opt) {
return text.toUpperCase().indexOf(term.toUpperCase()) >= 0
|| opt.attr("alt").toUpperCase().indexOf(term.toUpperCase()) >= 0
|| opt.attr("value").toUpperCase().indexOf(term.toUpperCase()) >= 0;
}
});
关于jquery - 如何使用多个参数过滤 select2 下拉列表,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/32733525/