[英]Jquery Mobile handling ajax requests
Currently I am working with Jquery mobile and encountered the following problem: 目前我正在使用Jquery mobile并遇到以下问题:
I am trying to load an list through ajax in a div though when I load a jquery mobile formatted list through ajax its not being templated by jquery mobile(the classes are not being applied) how can i fix this ? 我试图通过ajax在div中加载一个列表虽然当我通过ajax加载一个jquery移动格式化列表时它没有被jquery mobile模板化(这些类没有被应用)我该如何解决这个问题?
List page ( excluded the header etc to keep it short) 列表页面(排除标题等以保持简短)
<?php
$technicalListUrl = Helper::url("/technical_work_orders/overview/");
$visualListUrl = Helper::url("/visual_work_orders/overview/");
?>
<script type="text/javascript">
$(document).ready(function() {
$("#visualIcon").click(function() {
//load visual work orders
$('#workOrderList').load('<?php echo $visualListUrl?>');
});
$("#technicalIcon").click(function() {
//load technical work orders
$('#workOrderList').load('<?php echo $technicalListUrl ?>');
});
});
</script>
<div data-role="navbar" class="glyphish" data-iconpos="top" >
<ul>
<li ><a href="#" id="visualIcon" data-icon="custom">Optisch</a></li>
<li><a href="#" id="technicalIcon" data-icon="custom">Technisch</a></li>
</ul>
</div>
<div id="workOrderList" class="workOrders">
</div>
Ajax req view page Ajax req查看页面
<ul data-role="listview">
<?php foreach($workOrders as $workOrder):?>
<li>
<h3><?php echo $workOrder['VisualWorkOrder']['title']?></h3>
</li>
<?php endforeach;?>
</ul>
you have to destroy and recreate the page. 你必须销毁并重新创建页面。 See this link
看到这个链接
instead of: 代替:
$('.linkDiv').click(function(event) {
$('#contentDiv').load($(this).attr('href'));
return false;
});
you should do: 你应该做:
$('.linkDiv').click(function(event) {
$.get($(this).attr('href'), function(data) {
$('#contentDiv').html(data).page();
$( "div[data-role=page]" ).page( "destroy" ).page();
});
return false;
});
You need to refresh the list. 您需要刷新列表。 jQuery Mobile provides a methods to refresh the formatting on the list with the listview('refresh');
jQuery Mobile提供了一种使用listview('refresh')刷新列表格式的方法; command.
命令。
var list= $(".ul-list");
$(data.workorders).each(function (index) {
var url = '/something/' + this.ID;
var line = '<li><a href="' + url + '">' + this.Name + '</a></li>';
list.append(line);
$.mobile.loadPage(url, { showLoadMsg: false });
});
// update the jquery view
list.listview('refresh');
You need to refresh the data: 您需要刷新数据:
$('#workOrderList ul').listview('refresh');
$('.ui-page-active').page( "destroy" ).page();
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.