0

OK、PHP ページから JSON を取得できましたが、ユーザーがli内部をクリックしul#storesても実行されません。それはのようなものです

$("ul#stores").html("");
myMarkers = {"markers": data}

は更新されておらず、リストで見つけることができず、以下の機能は実行されません。最後に完全なコード。これが私の問題を説明する最良の方法であるかどうかはわかりません。

ライブデモ @ http://brightchoice.com.au/map.html

$("ul#stores li").on("click", function(event){
            var store = $(this).text();

            $("ul#stores").hide();
            $("#storeinfo").show();
            $.each(myMarkers.markers, function(i, data){

            if(store == data.name) {
                $("#storeinfo").append("<a href='map.html'><div class='greenbar'><div class='body'><div>  <span></span> </div> <p>Back</p></div></a></div><h1>"+data.name+"</h1>"+data.phone+"<br><br>"+data.address);

                //console.log(data.address);
                //console.log(data.state); // and more
             }
            });

            //searchlistings($(this).text());

        });

完全なコード

<script type="text/javascript">
// <![CDATA[
 $(document).ready(function(){
        //set up markers
         var myMarkers = {"markers": [{"id": 1,"name": "Belconnen","url_name": "belconnen","address": "Shop 176, 3rd Floor, Westfield Shopping Centre, Benjamin Way","suburb": "Belconnen","state": "act","postcode": 2618,"country": "Australia","phone": "(02) 6251 1838","fax": "","photo": "dcddfcb5c806b2255c611bd2d108cead.JPG","text": "","display": 1,"lat": -35.238428606,"lng": 149.065917134,"email": "tc.belconnen@telechoice.com.au","dealer_code": 63014,"region_id": 3,"type": 4}]};

//set up map options
        defaultmap();

        $("a#backtomap").on("click", function(event){
        defaultmap();
            $("ul#stores").show();
            $("#storeinfo").hide();
        });


        $("button#search").on("click", function(event){

            var postcode = $("input#postcode").val();
            $.getJSON("http://vipcashback.com/system/classes/core.php?task=postcode&mycode="+postcode, function(data) {
            $("ul#stores").html("");
              listings = {"markers": data}
                $("#map").mapmarker({
                    zoom : 10,
                    center : postcode+" australia",
                    markers : listings
                });

                $.each(myMarkers.markers, function(i, data){

                });
            });
        });

        $("ul#stores li").on("click", function(event){
            var store = $(this).text();
            alert(store);
            $("ul#stores").hide();
            $("#storeinfo").show();
            $.each(myMarkers.markers, function(i, data){

            if(store == data.name) {
                $("#storeinfo").append("<a href='map.html'><div class='greenbar'><div class='body'><div>  <span></span> </div> <p>Back</p></div></a></div><h1>"+data.name+"</h1>"+data.phone+"<br><br>"+data.address);

                //console.log(data.address);
                //console.log(data.state); // and more
             }
            });

            //searchlistings($(this).text());

        });


        function defaultmap(){
            $("#map").mapmarker({
                zoom : 3,
                center : 'Australia',
                markers : myMarkers
            });
        }

});

// ]]>
</script>
4

2 に答える 2

1

要素を動的に作成する場合は、次を使用する必要があります。

$('ul#stores li).live('click',function(){ ...});

ライブは、将来の要素をイベントに自動バインドできるように作成されています。

于 2012-05-30T00:15:45.733 に答える
0

プラグインコードを見ると、PHPページのJSONに欠けている経度と緯度が必要です

プラグインコード -

             if(latitude!="" && longitude!=""){
                var marker = new google.maps.Marker({
                    map: map, 
                    position: new google.maps.LatLng(latitude,longitude),
                    animation: google.maps.Animation.DROP,
                    icon: icon
                });

                // Set up markers with info windows 
                google.maps.event.addListener(marker, 'click', function() {
                    // Close all open infowindows
                    if (infowindow) {
                        infowindow.close();
                    }

                    infowindow = new google.maps.InfoWindow({
                        content: baloon_text
                    });

                    infowindow.open(map,marker);
                });
            }
        });
于 2012-05-30T00:47:22.303 に答える