0

我的 json 响应是这样的(根据萤火虫)

[
{
    "value": 1,
    "text": "Bill_Process_1",
    "selected": false,
    "imageSrc": "image.jpg",
    "description": "Bill_Process_1"
},
{
    "value": 2,
    "text": "Bill_Process_2",
    "selected": false,
    "imageSrc": "image.jpg",
    "description": "Bill_Process_2"
},
{
    "value": 3,
    "text": "Bill_Process_3",
    "selected": false,
    "imageSrc": "image.jpg",
    "description": "Bill_Process_3"
},
{
    "value": 4,
    "text": "Bill_Process_4",
    "selected": false,
    "imageSrc": "image.jpg",
    "description": "Bill_Process_4"
},
{
    "value": 5,
    "text": "Bill_Process_5",
    "selected": false,
    "imageSrc": "image.jpg",
    "description": "Bill_Process_5"
}

]

请帮我完成这段代码。它只显示空的下拉菜单。我对如何将它渲染到这里感到困惑..

        <div id="myDropdown"></div>
<script type="text/javascript">
    var jsonurl = 'dropDown.html';
    $.ajax({
          type: 'GET',
          url: jsonurl,
          data: {},
          success:function(data){
                 var options = $("#myDropdown");
                 $.each(data, function () {
                     alert(data);
                     options.append($("<option />").val(this.value).text(this.text));                        
                 });
             },
          error:function(){             
          }
        });     

    $('#myDropdown').ddslick({
        data : jsonurl,
        width : 300,
        selectText : "Select the bill process",
        imagePosition : "right",
        onSelected : function(selectedData) {
            //callback function: do something with selectedData;
        }
    });
</script>

我使用 spring @ResponseBody 返回这个 json 数组。

我使用 ddslick 作为我的下拉菜单。这里显示它是

ddslick 通过 jquery 代码下拉

现在我的输出是这样的。它不是以下拉列表的形式加载到 div 的数据,在网页上它一一显示为列表

我的输出

4

2 回答 2

1

你应该使用这样的东西:

 success:function(data){
     var options = $("#myDropdown");
     $.each(data, function () {
         options.append($("<option />").val(this.value).text(this.text));
     });
 },

在您的 AJAX 成功处理程序中解决下拉为空的问题。我不太确定你想在选择上实现什么。

于 2012-11-26T01:53:35.320 回答
1

试试这个

<script type="text/javascript">
var jsonurl = 'dropDown.html';
$.ajax({
      type: 'GET',
      url: jsonurl,
      data: {},
      success:function(myData){
          $('#myDropdown').ddslick({
               data : myData,
               width : 300,
               selectText : "Select the bill process",
               imagePosition : "right",
               onSelected : function(selectedData) {
                //callback function: do something with selectedData;
               }
          });
      },
      error:function(){             
      }
    });
</script>
于 2012-11-26T04:41:23.167 回答