Working import mechanism

This commit is contained in:
Nox Sluijtman 2023-11-01 17:45:00 +01:00
parent c41f60587b
commit 374238d472
2 changed files with 26 additions and 26 deletions

View file

@ -16,7 +16,6 @@
<input type="file" id="selectFiles" value="Import"/>
<button id="import">Import</button>
<textarea id="result" cols="30" rows="10"></textarea>
</main>
</body>
<script src="main.js"></script>

25
main.js
View file

@ -1,7 +1,8 @@
"using strict";
const menus = [ { "name": "Fruit", "items": [ "Banana", "Orange", "Pineapple", "Apple" ], "description":"What it says on the tin." }, { "name": "Genre", "items": [ "FFP", "Jiminy Cockthroat", "しひろ Cockthroat", "Spunk Gargle Weewee" ], "description":"Overal genre of the thinky thing" } ];
// const menus = [ { "name": "Fruit", "items": [ "Banana", "Orange", "Pineapple", "Apple" ], "description":"What it says on the tin." }, { "name": "Genre", "items": [ "FFP", "Jiminy Cockthroat", "しひろ Cockthroat", "Spunk Gargle Weewee" ], "description":"Overal genre of the thinky thing" } ];
function initLists (lists){
const menuContainer = document.getElementById('menu-container');
menus.forEach( menu =>{
@ -12,15 +13,16 @@ menus.forEach( menu =>{
dropdownMenu.id = menu.name.toLowerCase();
dropdownMenu.className = "dropdown-menu";
dropdownMenu.appendChild(menuTitle)
dropdownMenu.appendChild(description)
menuContainer.appendChild(dropdownMenu)
dropdownMenu.appendChild(dropdownSelect)
dropdownMenu.appendChild(menuTitle);
dropdownMenu.appendChild(description);
menuContainer.appendChild(dropdownMenu);
dropdownMenu.appendChild(dropdownSelect);
menu.items.forEach(item =>{
dropdownSelect.append(Object.assign(document.createElement('option'), {id:item.toLowerCase(), innerHTML:item}))
})
})
dropdownSelect.append(Object.assign(document.createElement('option'), {id:item.toLowerCase(), innerHTML:item}));
});
});
};
document.getElementById('import').onclick = function() {
const files = document.getElementById('selectFiles').files;
@ -28,13 +30,12 @@ document.getElementById('import').onclick = function() {
return false;
}
var fr = new FileReader();
const fr = new FileReader();
fr.onload = function(e) {
console.log(e);
var result = JSON.parse(e.target.result);
var formatted = JSON.stringify(result, null, 2);
document.getElementById('result').value = formatted;
const result = JSON.parse(e.target.result);
initLists(JSON.stringify(result, null, 2));
}
fr.readAsText(files.item(0));