Springタグを使用すると、選択ボックスの自動入力が機能しません。
以下の解決策は機能します、
<html>
<head></head>
<body>
<select id="articleLocation">
</select>
</body>
</html>
/*javascript*/
var jsonList = {"Table" : [{"stateid" : "2","statename" : "Tamilnadu"},
{"stateid" : "3","statename" : "Karnataka"},
{"stateid" : "4","statename" : "Andaman and Nicobar"},
{"stateid" : "5","statename" : "Andhra Pradesh"},
{"stateid" : "6","statename" : "Arunachal Pradesh"}]}
$(document).ready(function(){
var listItems= "";
for (var i = 0; i < jsonList.Table.length; i++){
listItems+= "<option value='" + jsonList.Table[i].stateid + "'>" + jsonList.Table[i].statename + "</option>";
}
$("#articleLocation").html(listItems);
});
以下の解決策(Springタグを使用)は機能しません。エラーメッセージは、「'option'タグは有効な'select'タグ内でのみ使用できます。」です。
<html>
<head></head>
<body>
<form:select path="articleLocation">
</form:select>
</body>
</html>
/*javascript*/
var jsonList = {"Table" : [{"stateid" : "2","statename" : "Tamilnadu"},
{"stateid" : "3","statename" : "Karnataka"},
{"stateid" : "4","statename" : "Andaman and Nicobar"},
{"stateid" : "5","statename" : "Andhra Pradesh"},
{"stateid" : "6","statename" : "Arunachal Pradesh"}]}
var listItems= "";
for (var i = 0; i < jsonList.Table.length; i++){
listItems+= "<form:option value='" + jsonList.Table[i].stateid + "' label='" + jsonList.Table[i].statename + "'/>";
}
$("#articleLocation").appendTo(listItems);