要素を追加するときにバインドしているイベントを手動で呼び出すことで、なんとか方法を見つけることができました。
// Instead of having to "click" the select fields
// I'd like to populate the <option> tags everytime a new select item is injected into the DOM.
$(document).on("click", "select.countrylist", function() {
var select = $(this);
$(countries).each(function(i) {
var option = $("<option></option>").attr("value", this.Key).text(this.Value.EnglishName);
if (this.Key === select.data('selected')) option.prop("selected", true);
select.append(option);
select.get().selectedIndex = i;
});
});
// populate all existing selects
$("select.countrylist").click();
// create new select and populate it
$('#test').click(function() {
var x = $('<select data-selected="USA" class="countrylist"></select>').appendTo("body");
// manually trigger a click which causes populating of select
x.click();
});
実際の例については、この JSFiddle を参照してください
クリック イベントを select 自体ではなく $(document) にバインドする必要があることに注意してください (機能しません)。
助けてくれてありがとう!