2013-08-25 17 views
6

Używam jQuery mobile 1.9.1 min na PhoneGap.
Mam listę, gdzie każdy Iten na kliknięcie otwiera działania popup:jQuery mobile open popup z popup

function showActions(index){ 
    selectedIndex = index; 
    $("#actionPopup").popup("open", {positionTo: '#list li:nth-child('+ index +')'}); 
} 
<div data-role="popup" id="actionPopup" data-overlay-theme="a"> 
    <a href="#" data-rel="back" data-role="button" data-theme="a" data-icon="delete" data-iconpos="notext" class="ui-btn-right">Close</a> 
     <ul data-role="listview"> 
       <li data-role="divider">Actions</li> 
       <li data-icon="false" onclick="showDetails();">action1</li> 
       <li data-icon="false">action2</li> 
       <li data-icon="false">action3</li> 
       <li data-icon="false">action4</li> 
      </ul> 
     </div> 

Po naciśnięciu na działania1 z showDetails() sposób je nazywa, ale drugie okienko nie jest widoczne.

function showDetails(){ 
    console.log("showDetails"); 
    $("#infoPopup").popup("open"); 
} 
<div data-role="popup" id="infoPopup"> 
      <a href="#" data-rel="back" data-role="button" data-theme="a" data-icon="delete" data-iconpos="notext" class="ui-btn-right">Close</a> 
      <div id="infoContent"> 
       <table> 
        <tr id="eventcode"> 
         <td>test1:</td> 
         <td>&nbsp;</td> 
        </tr> 
        <tr id="eventtype"> 
         <td>test2:</td> 
         <td>&nbsp;</td> 
        </tr> 
       </table> 
      </div> 
     </div> 

Co mogę zrobić?

Odpowiedz

10

Moje rozwiązanie

$.mobile.switchPopup = function(sourceElement, destinationElement, onswitched) { 
    var afterClose = function() { 
     destinationElement.popup("open"); 
     sourceElement.off("popupafterclose", afterClose); 

     if (onswitched && typeof onswitched === "function"){ 
      onswitched(); 
     } 
    }; 

    sourceElement.on("popupafterclose", afterClose); 
    sourceElement.popup("close"); 
}; 
1

Wygląda na to, że wyskakujące okienka nie są possible.

Rozwiązanie:

$(document).on("pageinit", function() { 
    $('.popupParent').on({ 
     popupafterclose: function() { 
      setTimeout(function(){ $('.popupChild').popup('open') }, 100); 
     } 
    }); 
}); 
1

Użyłem tego kodu, aby przełączyć się z popup popup to działa dobrze.

function switchpop() 
{ 
    $('#popupMenu').popup('close'); 
    $("#popupMenu").bind({popupafterclose: function(event, ui) 
      { 
       $("#notes").popup("open"); 
      } 
      });     
} 
3

użyłem tej prostej funkcji do obejścia:

function myPopup(myPage) { 
    history.back(); 
    setTimeout(function() { 
     $(myPage).popup('open'); 
    }, 100); 
} 
0

Po czterech godzinach walki z tym, że zmniejsza się problem tak:

Jest to funkcja przycisku click na pierwszym wyskakującym okienku:

$('#popupCall').popup('close'); 

    window.setTimeout(function() { $('#popupContact').popup('open') }, 50); 
3

@Rakoo ma fajną odpowiedź. Tutaj jest wydajniejsza wersja:

$.mobile.switchPopup = function(sourceElement, destinationElement, onswitched) { 
    sourceElement.one("popupafterclose", function() { 
     destinationElement.popup("open") 
     !onswitched || typeof onswitched !== "function" || onswitched() 
    }).popup("close") 
}; 

Jeśli nie potrzebujemy onswitched funkcję i nie dodajemy go do $ Aparaty fotograficzne, może być to krótka i prosta:

$('#popup1').one("popupafterclose", function(){$('#popup2').popup("open")}).popup("close")