[英]How to create dropdown list from a json array in a function in HTML with javascript?
大约有五十个条目,我知道我还应该有一些迭代器,以便我可以在任务后继续拉动任务并自动填充下拉列表。 我什至在考虑如何启动它时都遇到了麻烦,我正在和某人谈论动态填充,我不确定如何在我的场景中启动。
function table_generate_from_json(array,table_id){
table_html=""
function create_table_row(item,index){
$("td[field='task_name']").html(html_link_from_todoist_task_dictionary(item))
$("td[field='task_priority']").html(item.type)
$("td[field='task_due_date']").html(moment(item.due_date_utc).fromNow())
$("td[field='task_created_date']").html(moment(item.date_added).fromNow())
$("tr").attr('id',item.id)
table_html=table_html+$(table_id).html()
}
array.forEach(create_table_row)
$(table_id).html(table_html)
}
//todoist_table_list
function todoist_task_list_generate(array){
table_generate_from_json(array,'#todoist_table_list_tbody')
}
以此为样本
var json_a=[ { user:"user1hp",pass:"pass1" }, { user:"rexuser2",pass:"pass2" } , { user:"rexuser3",pass:"pass3" } ]; let l=0; l=json_a.length; let i=0; let select=document.getElementById("sel"); for(i=0;i<l;i++) { var opt = document.createElement('option'); opt.value = json_a[i].user; opt.innerHTML = json_a[i].user; select.appendChild(opt); }
<!DOCTYPE html> <html> <head> <title>JSON ARRAY LIST</title> </head> <body> <select id="sel"> </select> </body> </html>
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.