2012-09-10 89 views
0

我正在使用http://designwithpc.com/Plugins/ddSlick#demo。一個插件,用圖像,文本等自定義下拉菜單。 我試圖從下拉列表中選擇一個選擇選項時獲取文本,但我的瀏覽器控制檯日誌說未定義。我已經嘗試將數據放入第7行的變量中,但仍然給出了相同的結果。從選擇下拉菜單中獲取數據

$('#myDropdown').ddslick({ 
    data:ddData, 
    width:300, 
    selectText: "Select your preferred social network", 
    imagePosition:"right", 
    onSelected: function(selectedData){ 
     var selectedData = $('#myDropdown').data('ddslick'); 
     console.log(selectedData.text); 
    } 
}); 

這是ddData的結構:

var ddData = [{ 
    text: "Facebook", 
    value: 1, 
    selected: false, 
    description: "Description with Facebook", 
    imageSrc: "http://dl.dropbox.com/u/40036711/Images/facebook-icon-32.png" 
}, { 
    text: "Twitter", 
    value: 2, 
    selected: false, 
    description: "Description with Twitter", 
    imageSrc: "http://dl.dropbox.com/u/40036711/Images/twitter-icon-32.png" 
}, { 
    text: "LinkedIn", 
    value: 3, 
    selected: true, 
    description: "Description with LinkedIn", 
    imageSrc: "http://dl.dropbox.com/u/40036711/Images/linkedin-icon-32.png" 
}, { 
    text: "Foursquare", 
    value: 4, 
    selected: false, 
    description: "Description with Foursquare", 
    imageSrc: "http://dl.dropbox.com/u/40036711/Images/foursquare-icon-32.png" 
}]; 

回答

0

我通過JSON對象獲得的數據。

早期它只返回[對象的對象]

<div id="myDropdown"></div> 
    <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) { 
         alert(selectedData); 
        } 
       }); 
      }, 
      error : function() { 
      } 
     }); 
    </script> 

但按我的螢火它顯示了我這樣的

[ 
    { 
     "value":1, 
     "text":"Process_1", 
     "selected":false, 
     "imageSrc":"images//priyan.jpg", 
     "description":"Process_1" 
    }, 
    { 
     "value":2, 
     "text":"Process_2", 
     "selected":false, 
     "imageSrc":"images//priyan.jpg", 
     "description":"Process_2" 
    }, 
    { 
     "value":3, 
     "text":"Process_3", 
     "selected":false, 
     "imageSrc":"images//priyan.jpg", 
     "description":"Process_3" 
    } 
    ] 

JSON響應,那麼我改成了這樣的..

onSelected : function(selectedData) { 
         alert(selectedData); 
        } 

onSelected : function(myData) { 
         alert(myData.selectedData.text); 
        }