0

これが私の場合です:

$('select').select2();

$('select').on('change', function () {
    // calling a function
    myFunction();
});

function myFunction() {
    // changes my select values
    // so I need to update the select for seing the news values
    $('select').trigger('change');

    // hehe I fire the change event so myFunction is called again and again
}

その動作を回避するにはどうすればよいですか?よろしく...

4

1 に答える 1

0

これは Select2 のバグです。次のコードで同じ問題が発生しました。

var FID = $(location).attr('href').split("/")[5];
$('#facility').children().each(function () {
    if ($(this).val().trim() == FID.trim()) {
        $(this).attr('selected', 'selected').trigger('change');
    }
});

以下は理想的ではありませんが、問題を解決します。Select2オプションを再定義する必要があることに注意してください(私のものを示しています)。

var FID = $(location).attr('href').split("/")[5];
$('#facility').children().each(function () {
    if ($(this).val().trim() == FID.trim()) {
        $(this).attr('selected', 'selected');
        $('#facility').select2({
            placeholder: "",
            minimumResultsForSearch: -1
        });
    }
});
于 2013-06-06T13:25:03.460 に答える