0
私は同じページで編集するために入力内にダイナミックデータを表示するポップアップモーダルですselect2を問題なく使用していますが、 jQueryの成功の上にそれを初期化している(またはそれはそれが何をすべきかだ)このモーダルを使用していても、ロード後に初期化されていない:Select2がAjaxを使って動的に作成されたときにブートストラップモーダルで初期化されない
<div class="modal fade" id="edit" role="dialog">
<div class="modal-dialog">
<!-- Modal content-->
<div class="modal-content">
<div class="modal-header">
<button type="button" class="close" data-dismiss="modal">×</button>
<h4 class="modal-title">Edit</h4>
</div>
<div class="modal-body">
<div class="company_edit">
</div>
</div>
<div class="modal-footer">
<button type="button" class="btn btn-default" data-dismiss="modal">Close</button>
</div></div></div> </div>
とjQuery:
$('.btn.btn-primary.btn-xs').on('click', function() {
var company_id = $(this).attr('value');
$.ajax({
type: 'post',
url: 'dist/php/info_to_edit.php',
data: 'post_id=' + company_id,
success: function (r)
{
$(".select2").select2({
tags: true,
tokenSeparators: [',', ' ']
});
// now you can show output in your modal
$('#edit').modal('show'); // put your modal id
$('#edit').find('.company_edit').html(r);
}});});
とPHPのスニペット:
echo '<select name="countries_import[]" class="form-control select2" multiple="multiple" id="import_select"></select>';
前
を設定してみてください。私の問題を解決していただきありがとうございます。 –