1

当我使用 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);
4

0 回答 0