我有一个对象
var myObject = { 3: 'Three', 6: 'Six'};
我想在下拉列表中填充这些值,如下所示:
var statusDropdown = document.createElement('select');
for (var item in myObject ) {
var option = document.createElement("option");
option.text = item.value; //this is undfined item = "Three", or "Six"
option.value = item.key; //this is undfined item = "Three", or "Six"
statusDropdown.options.add(option);
}
因为 in 似乎是要走的路,但我正在尝试做关键和价值,而不仅仅是价值。这将允许我将第一个下拉选项的键设置为 3,第二个下拉选项设置为 6