Gibt es eine Möglichkeit, eine multiple Dropdown-Feld aus einer Liste von Arrays zu erhalten, ohne die Informationen in den HTML-Code fest codieren zu müssen? So dass bei der Auswahl jeder Kategorie die relevante Unterkategorie abfällt. Die Liste sieht wie folgt aus:Javascript mehrere Dropdown-Box
var listData = [
{
"title": "Meeting Room",
"category": "Forms",
"url": "https://www.google.co.uk/"
},
{
"title": "Book a Car",
"category": "Forms",
"url": "https://www.google.co.uk/"
},
{
"title": "Stationery",
"category": "Forms",
"url": "https://www.google.co.uk/"
},
{
"title": "Hospitality",
"category": "Forms",
"url": "https://www.google.co.uk/"
},
{
"title": "Communications",
"category": "News",
"url": "https://blogs.office.com/"
},
{
"title": "Industries",
"category": "News",
"url": "https://blogs.office.com/"
},
{
"title": "Policy",
"category": "News",
"url": "https://blogs.office.com/"
},
{
"title": "Get started",
"category": "Information",
"url": "https://support.office.com/"
},
{
"title": "What do you need",
"category": "Useful Information",
"url": "https://support.office.com/"
},
{
"title": "Accessibility features",
"category": "Useful Information",
"url": "https://support.office.com/"
},
{
"title": "Videos",
"category": "Useful Information",
"url": "https://support.office.com/"
}
]
Die Daten, die Sie Kategorien anzeigen, aber keine Unterkategorien (es sei denn, „Nützliche Informationen“ ist eine Unterkategorie von „Information“ betrachtet). Aber wie auch immer, ja, Sie können JS schreiben, das die Optionen eines ausgewählten Elements aktualisiert, wenn ein anderes Element geändert wird. – nnnnnn
@nnnnnn um das zu erreichen, jeder Vorschlag wie? soll ich eine for-Schleife benutzen? – Alessandro
Sie können eine Schleife verwenden, ja. http://StackOverflow.com/Questions/8674618/Adding-Option-to-select-with-javascript – nnnnnn