0

How do I check if an item I want to add into the select input, has already been added? Here is my code:

    $("#FilterBatch").multiselect
    ({
        noneSelectedText: "Select Batch",
        selectedList: 1,
        multiple: false,
        click: function (event, ui) {
            //do something
        }
    });


$.each(objJobInfo, function (index, value) {
    if (value does not already exist in the select input) { <=== how do I check this?????
        $('#FilterStatus').append($('<option>', {
            value: value.Status,
            text: objJobInfo[index]["Status"]
        }));
    }
});

Thank you

4

1 回答 1

1

Basically, you can check the length. If the length is equal to 0, you can add your value.

$.each(objJobInfo, function (index, value) {
    if ($("#yourSelect option[value='yourValue']").length === 0 { //value does not exist so add
        $('#FilterStatus').append($('<option>', {
            value: value.Status,
            text: objJobInfo[index]["Status"]
        }));
    }
});
于 2013-06-14T01:52:34.770 回答