0
私はBS3モーダルイベントを使用する状況があり、私のアプリケーションの機能は公開されたメソッド(モジュールのパターンを明らかにする)でオブジェクトにラップされています。私はBSから受け取ったイベントを持っていますが、これは私の$ thisがAppオブジェクトではなくEventオブジェクトを指しています。 私は最高のものであるように思わjQueryのプロキシ、とjquery this contextを試してみましたが、何らかの理由で、物事はjQueryこのコンテキストはコンテキスト内の要素を指します
var globalAppDef = (function() {
function modalFilters() {
$('#filtersMore')
.on('show.bs.modal', (event) => {
const sourceElement = $(event.relatedTarget);
$(sourceElement.data().filters).removeClass('hidden');
})
/*
* Transfer the proper @this of the event outside the {globalAppDef} Object
*/
.on('hidden.bs.modal', $.proxy((event) => {
$(this).find(".form-list-items-1").addClass('hidden');
$(this).find(".form-list-items-1").addClass('hidden');
}, this));
}
return modalFilters: modalFilters
}
});
var globalApp = new globalAppDef();
globalApp.initialize();
$(document).ready(function() {globalApp.modalFilters()});
私は何を達成するためには二hidden.bs.modal上にある私のために働いていませんでした$ thisは、$( '#filtersMore')要素であるMy Modalを指すようにします。