2013-04-29 91 views
1

我已经创建了我的web应用程序的登录页面使用php,在那里我将结果转换成json并用jquery抓取列表。现在我的问题是,该列表是超链接到另一个页面。因此,当用户从列表中选择一个名字时,他们应该被重新指向另一个页面,并且看到该患者的所有信息。但我不知道如何抓住并在另一页上显示选定的患者。使用jquerymobile和php创建一个移动应用程序

理想情况下,我想创建另一个函数,它从php文件获取json结果并将其保存在jquery数组中。现在当用户选择一个病人时。然后将患者的身份与列表中的身份进行比较,如果匹配,则显示与该患者相关的所有内容,但显示在另一页上。

var url = 'http://brandon.walesalami.com/nurseD.php'; 
$.get(url,function (data){ 
    //var renderHtml = '<div data-role="list-view"></div>'; 
    var listView = $('<ol data-role="listview" data-inset="true"></ol>'); 
    for (var i in data.patient) 
     { 
      var li = $('<li class="patientSel"><a href="#profile" class="' + data.patient[ i ].id + '">' + data.patient[ i ].name + '</a></li>').appendTo(listView); 
     } 
     $('#co').replaceWith(listView); 
    }, 'json'); 

回答

1

我的其他答案请看:jQuery Mobile: Sending data from one page to the another,在那里你会找到一些解决您的问题。

基本上你想是这样的:http://jsfiddle.net/Gajotres/eAYB9/

$(document).on('pagebeforeshow', '#index', function(){  
    $('#test-listview li a').each(function(){ 
     var elementID = $(this).attr('id');  
     $(document).on('click', '#'+elementID, function(event){ 
      if(event.handled !== true) // This will prevent event triggering more then once 
      { 
       localStorage.itemID = elementID; // Save li id into an object, localstorage can also be used, find more about it here: https://stackoverflow.com/questions/14468659/jquery-mobile-document-ready-vs-page-events 
       $.mobile.changePage("#second", { transition: "slide"}); 
       event.handled = true; 
      }    
     }); 
    }); 
}); 

$(document).on('pagebeforeshow', '#second', function(){  
    $('#second [data-role="content"]').html('You have selected Link' + localStorage.itemID); 
}); 
+0

谢谢。它完美的作品。现在我该如何显示所选患者的姓名? – Wale 2013-05-02 06:01:56

相关问题