php - How do you to add page slide to a dynamic created list using jquery mobile? -
here html populated listview. have link grabbed php script aswell. put page slide function on click event. wont allow me html in script
<div data-role="content"> <script type="text/javascript"> $(document).on("pagebeforeshow", "#index1", function() { $(function(){ var items=""; $.getjson("check-events.php",function(data){ $.each(data,function(index,item) { items+="<li><a href="+item.col1+"?eventid="+item.id+">"+item.col2+"<p></p><p>"+item.col3+"</p></li>"; }); $("#contacts").append(items); $("#contacts").listview("refresh"); }); }); }); </script> <div data-role="fieldcontain"> <ul id="contacts" data-role="listview" data-divider-theme="b" data-inset="true"> <li data-role="list-divider" role="heading"> list view </li> </ul> </div>
where add piece code. keeps producing error when add this
items+="<li><a href="+item.col1+"?eventid="+item.id+" data-transition="slide">"+item.col2+"<p></p><p>"+item.col3+"</p></li>";
any ideas
working solution php
$data = array(); while($rowa = mysql_fetch_array($a, mysql_assoc)) { $row_array['id'] = $rowa['eventid']; $row_array['col1'] = "index.html"; $row_array['col2'] = $rowa['eventname']; $row_array['col3'] = date("d js f y",strtotime($rowa[enddate])); $row_array['col4'] = "slide"; array_push($data,$row_array); } echo json_encode($data); }
changed html
items+="<li><a href=\""+item.col1+"?eventid="+item.id+"\" data-transition=\""+item.col4+"\">"+item.col2+"<p></p><p>"+item.col3+"</p></li>";});
you need escape quotes when putting in variables (\"
)
items+="<li><a href=\""+item.col1+"?eventid="+item.id+"\" data-transition=\""slide"\">"+item.col2+"<p></p><p>"+item.col3+"</p></li>";
but, on side note, should letting jquery create elements you. see: https://stackoverflow.com/a/4158203/1178781
Comments
Post a Comment