JQuery Mobile gets the id of the clicked element that caused the page transition after the page transition

I have a jquery mobile app with two "pages". On the first page is a Google map, and on the second page is a list of buildings, where each element of the list has an identifier associated with it. When a user clicks on a building, the map is designed to pan this building and display a marker. However, one of the features of jQuery mobile is that I have to call google.maps.event.trigger(map, 'resize')and map.panTo(somePosition)after the conversion page, otherwise the card will look funky. I am using jQuery Mobile event pageshowfor this. My question is, is there anything in the event handler arguments, pageshowor is there any way to associate something with the event handler argumentspageshowthat will allow me to identify the identifier of the list item that was clicked, which caused the page to jump in the first place, so I can use this to determine where to copy the map?

At the moment, I need to do this in a circular way, where I click the click event of the selected list item, save the selected list item in a global variable, and then use this global variable later when in the event handler pageshow.

So something like:

var selectedBuilding;

$('a.buildingSelect').click(function(e) {
    e.preventDefault();
    selectedBuilding = $(this).attr("data-buildingNum");
});


$('div').live('pageshow',function(event, ui){
    if (ui.prevPage.attr('id') === "buildingSelect") {
        google.maps.event.trigger(map, 'resize');
        map.panTo(selectedBuilding);
    }
});

, , , , "" . pageshow - , , , , , . , , , . , pageshow, , .

jQuery javascript , , , . javascript Chrome, , , ui pageshow, , , .

+3
2

pageshow buildingSelect , : .live( eventType, eventData, handler ) from http://api.jquery.com/live/.

die pageshow , . , , . , , , .

EDIT: "" die. , , $('div').die(), , : http://api.jquery.com/die/

+1

Milimetric , :

var selectedBuilding;

function rejigMap(event ui) {
    google.maps.event.trigger(map, 'resize');
    map.panTo(selectedBuilding);
    $('div').die('pageshow', rejigMap);
}

$('a.buildingSelect').click(function(e) {
    e.preventDefault();
    selectedBuilding = $(this).attr("data-buildingNum");
    $('div').live('pageshow', rejigMap);
});

live listhow listener, , (die ing) , , , rejigMap, pageshow, , "" - . , , .live(eventType, eventData, handler), rejigMap, .

0

All Articles