$("input[name='row[unit_nature]']").addClass("selectpage").data("source", "dictionary/allocation/search").data("primaryKey", "name").data("field", "name").data("orderBy", "id desc"); $("input[name='row[organisation_type]']").addClass("selectpage").data("source", "dictionary/allocation/index").data("primaryKey", "organisation_type").data("field", "organisation_type").data("orderBy", "id desc").data("groupBy", "organisation_type").data("params", function (obj) { return {custom: {unit_nature: $("input[name='row[unit_nature]']").val()}}; }); 怎么能把下拉的重复值去掉

$("input[name='row[unit_nature]']").addClass("selectpage").data("source", "dictionary/allocation/search").data("primaryKey", "name").data("field", "name").data("orderBy", "id desc"); $("input[name='row[organisation_type]']").addClass("selectpage").data("source", "dictionary/allocation/index").data("primaryKey", "organisation_type").data("field", "organisation_type").data("orderBy", "id desc").data("groupBy", "organisation_type").data("params", function (obj) { return {custom: {unit_nature: $("input[name='row[unit_nature]']").val()}}; }); 怎么能把下拉的重复值去掉
用户252301526
2024年12月26日
|
浏览 107

您可以使用以下 jQuery 代码来去除下拉列表中的重复值:

复制代码
// 对于第一个下拉列表
$("input[name='row[unit_nature]']").addClass("selectpage").data("source", "dictionary/allocation/search").data("primaryKey", "name").data("field", "name").data("orderBy", "id desc");

// 对于第二个下拉列表
$("input[name='row[organisation_type]']").addClass("selectpage").data("source", "dictionary/allocation/index").data("primaryKey", "organisation_type").data("field", "organisation_type").data("orderBy", "id desc").data("groupBy", "organisation_type").data("params", function (obj) {
    return {custom: {unit_nature: $("input[name='row[unit_nature]']").val()}};
});

// 去除重复值
var seen = {};
$("input[name='row[organisation_type]'] option").each(function() {
    if (seen[$(this).text()]) $(this).remove();
    else seen[$(this).text()] = true;
});

这段代码会遍历第二个下拉列表中的选项,并在遇到重复值时将其移除,以确保列表中不含有重复的选项。

我要提问
复制内容
分享给好友
AI编程问答网 免责声明:
以上内容除特别注明外均来源于网友提问,AI编程问答网回答,权益归原著者所有;
 
上一篇:不起作用