0

http://designwithpc.com/Plugins/ddSlick#demoを使用しています。画像、テキストなどでドロップダウン メニューをカスタマイズするプラグインです。ドロップダウンから選択オプションの 1 つを選択したときにテキストを取得しようとしていますが、ブラウザのコンソール ログには未定義と表示されます。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"
}];
4

1 に答える 1

0

Json Object でデータを取得しました。

以前は [object Object] のみを返します

<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>

しかし、私のfirebugによると、次のようなjson応答が表示されます

[
   {
      "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"
   }
   ]

それから私はそれをこのように変更しました..

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

onSelected : function(myData) {
                        alert(myData.selectedData.text);
                    }   
于 2012-12-01T12:00:27.960 に答える