I know that the question has already been asked but it did not solve my problem! That's why I ask again!
I have a JavaScript file with a variable and a function. I would like to apply this function in another JavaScript file.
For that, I have to import a file into another one. And I can not do it despite attempts via internet tutorials ...
My code so far:
countries.js:
var isoCountries = {
'AF' : 'Afghanistan',
'AX' : 'Aland Islands',
[...]
'FK' : 'Falkland Islands (Malvinas)',
'FO' : 'Faroe Islands',
'FJ' : 'Fiji',
'FI' : 'Finland',
'FR' : 'France',
[...]
'YE' : 'Yemen',
'ZM' : 'Zambia',
'ZW' : 'Zimbabwe'
};
function getCountryName (countryCode) {
if (isoCountries.hasOwnProperty(countryCode)) {
return isoCountries[countryCode];
} else {
return countryCode;
}
}
loadJSON.js in which I need this function
$('countries.js', function() {
alert("Script loaded but not necessarily executed.");
})
$.getJSON('js/issuers.json', function(donnees) {
let jsonData = "";
let count = 1;
$.each( donnees, function( key, val ) {
if (count === 1) {
jsonData += "<div class='row'>"
}
jsonData +=
"<div class=\"one-card col-lg-3 col-md-6 wow fadeInUp\">"+
"<div class=\"card\">"+
"<div class=\"card-container-img\">"+
"<img src=\""+val.logo+"\"+ class=\"card-img-top\" alt=\""+val.name+"\">"+
"</div>"+
"<div class=\"card-body\">"+
"<h2 class=\"issuer-name\">"+val.name+"</h2>"+
"<p class=\"issuer-important\"><span class=\"country\">"+getCountryName(val.country)+"</span> <span class=\"continent\">"+val.continent+"</span></p>"+
"<p class=\"issuer-number\">"+val.address+"</p>"+
"<p class=\"declaration\">"+
"<i class=\"icon-quote-start quote\"></i>"+
val.intentDeclaration+
"<i class=\"icon-quote quote\"></i>"+
"</p>"+
"<p class=\"collapse multi-collapse"+key+" declaration-all\" id=\"multiCollapseI"+key+"\">"+
"<i class=\"icon-quote-start quote\"></i>"+
val.intentDeclaration+
"<i class=\"icon-quote quote\"></i>"+
"</p>"+
"<div class=\"validator\">"+
"<p class=\"issuer-important\">Autorisé par"+
"<a href=\"http://bcdiploma.com\"target=\"_blank\">"+
"<img src=\""+"img/icons/bcdiploma-logo-header.svg"+"\" class=\"card-img-bottom\" alt=\"bcdiploma\">"+
"</a>"+
"</p>"+
"</div>"+
"<a data-toggle=\"collapse\" data-target=\".multi-collapse"+key+"\" aria-expanded=\"false\" >"+
"<i class=\"ti-plus\" id=\"plus\"></i>"+
"</a>"+
"<div class=\"collapse multi-collapse"+key+"\" id=\"multiCollapseV"+key+"\">"+
"<p>"+
"Blockchain Certified Data SAS - 84, av Albert 1er 92500 Rueil-Malmaison FRANCE"+
"<p class=\"issuer-number\">0x7332ea1229c11c627c10eb24c1a6f77bced1d5c1</p>"+
"</p>"+
"</div>"+
"</div>"+
"</div>"+
"</div>"
if (count === 4) {
jsonData += "</div>"
}
count = (count%4) + 1;
});
$(".testjson").html(jsonData);
});
// TABLE
$.getJSON('js/issuers.json', function(donneestable) {
let jsonDataTable = "";
$.each( donneestable, function( key, val ) {
jsonDataTable +=
"<tr>"+
"<td style='display:none;'>"+val.logo+"</td>"+
"<td><h3>"+val.name+"</h3></td>"+
"<td>"+val.date+"</td>"+
"<td><div class='number-table'>"+val.address+"</div></td>"+
"<td>"+val.validatorName+"</td>"+
"<td>"+val.country+"</td>"+
"<td>"+val.continent+" <i class='ti-plus' id='plus-list'></i></td>"+
"<td style='display:none;'>"+val.legalReference+"</td>"+
"<td style='display:none;'>"+val.intentDeclaration+"</td>"+
"<td style='display:none;'>"+val.validatorLegalReference+"</td>"+
"<td style='display:none;'>"+val.validatorAddress+"</td>"+
"<td style='display:none;'>"+val.website+"</td>"+
"<td style='display:none;'>"+val.validatorLogo+"</td>"+
"<td style='display:none;'>"+val.validatorWebsite+"</td>"+
"</tr>"
});
$(".table-json").html(jsonDataTable);
});
// ROW CHILD
function format ( d ) {
// `d` is the original data object for the row
return '<td class="background no-border">' +
'<img class="logo-table" src="'+d[0]+'"/>' +
'</td>' +
'<td class="background no-border"><p class="title-rowchild">Références légales</p><p class="p-rowchild">'+d[7]+'</p>'+
'<p class="title-rowchild">Déclaration d\'intention</p><p class="p-rowchild-end">'+d[8]+'</p>'+
'<a class="website" target=_blank href="'+d[11]+'">Visiter le site</a>'+
'</td>'+
'<td class="no-border">'+
'<img style="width: 20%;" src="'+d[12]+'"/>' +
'<p class="title-rowchild">Références légales</p><p class="p-rowchild">'+d[9]+'</p>'+
'<p class="title-rowchild">Adresse de la Blockchaine</p><p class="p-rowchild-end">'+d[10]+'</p>'+
'<a class="website" target=_blank href="'+d[13]+'">Voir la liste</a>'+
'</td>'
;
}
The alert (for testing) doesn't working