Following a previous answered question, I'm iterating over keys in JSON and putting them inside <option>
tags in a select
menu. It works fine, but I want it synchronized so that it's removed automatically if a key is removed from the JSON data.
My JSON data:
{
"config": {
"title key1": [
"hello",
"hola",
"mi seudónimo es fivethous"
],
"title key2": [
"hejsan",
"tjena"
],
"title key3": [
"random",
"hello",
"good bye"
]
},
"info": [
"Hello world,",
"how are you doin?",
"Its not going to well for me unfortunately."
]
}
I have multiple keys iterated, each in it's own function. In this particular function I'm iterating over all the keys inside the parent config
key.
var info;
var config;
function json() {
$.getJSON("/static/_info",
function(d) {
info = d.info;
config = d.config;
});
}
function tvshows() {
tvShows = [];
$('option#show').each(function() {
tvShows.push($(this).text());
});
$.each(config, function(show) {
if (!tvShows.includes(show)) {
$('#select_tvshow').prepend('<option id="show" value="' + show + '">' + show + '</option>');
}
});
}
function updatelog() {
-||-
}
function updates() {
json();
updatelog();
tvshows();
}
var interval = window.setInterval(updates, 2000);
Also, it would be great if this applied likewise to values.
I have tried as many different approaches I can think of, how do I accomplish this? Thanks in advance.