В javascript я загружаю несколько скриптов, а затем хочу запустить функцию после. Проблема в том, что мое обещание выполняется слишком рано. Он запускается после загрузки каждого файла, но мне нужно подождать, пока они все не будут добавлены в DOM и полностью выполнены.
(function() {
function getFile(path) {
return $.get(path, function (data) {
$("body").append(data);
});
}
$.when.apply($, [
// load all the individual components
"components/once/ti-snackbar/ti-snackbar.html",
"components/once/ti-not-supported/ti-not-supported.html",
"components/once/ti-drawer/ti-drawer.html",
"components/widgets/ti-company-table-row/ti-company-table-row.html",
"components/widgets/ti-chip-set/ti-chip-set.html",
"components/widgets/ti-list/ti-list.html",
"components/widgets/ti-user-card/ti-user-card.html",
"components/widgets/ti-tabs/ti-tabs.html",
"components/widgets/ti-data-table/ti-data-table.html",
"components/forms/ti-new-company-form/ti-new-company-form.html",
"components/forms/ti-edit-company-form/ti-edit-company-form.html",
"components/pages/ti-page-inquire/ti-page-inquire.html",
"components/pages/ti-page-companies/ti-page-companies.html",
"components/pages/ti-page-report/ti-page-report.html",
"components/pages/ti-page-admins/ti-page-admins.html",
"components/pages/ti-page-contacts/ti-page-contacts.html",
"components/pages/ti-page-policy/ti-page-policy.html",
"components/pages/ti-page-manual/ti-page-manual.html",
"components/pages/ti-page-404/ti-page-404.html",
"components/tabs/ti-tab-name/ti-tab-name.html",
"components/tabs/ti-tab-tags/ti-tab-tags.html",
"components/tabs/ti-tab-status/ti-tab-status.html",
"components/tabs/ti-tab-restriction/ti-tab-restriction.html",
"components/tabs/ti-tab-other/ti-tab-other.html"
].map(getFile)).then(function() {
// render the full app after all components load
getFile("components/once/ti-app/ti-app.html");
});
})();
Как я могу это исправить?
Примечание: каждый HTML-файл имеет <script>
и <template>
.
Спасибо