我的代码有两个奇怪的问题,我用它来输入一些数据,以便在列表视图中使用。这是我的javascript:
function getOrders(status, url) {
$(function () {
//check if url from pagination
if (!url) {
url = api_url + '/orders/?callback=?&status=' + status;
} else {
url = root_url + url + '&callback=?';
}
$.mobile.loading('show');
$.getJSON(url, null, function (d) {
//declare a variable with which to build our output (it's best to buffer output and only do one append at the end since DOM manipulation is CPU expensive)
var output = '';
//iterate through the data (we could also get rid of the jQuery here by using `for (key in data) {
$.each(d.objects, function (index, value) {
output += '<li><a id="' + value.reference + '" href="view_order.html" class="view_order"><h3>' + value.reference + ' - ' + value.client.company + '</h3><p>' + value.order_date + ' ' + value.user.username + '</p></a><a href="asd" data-icon="gear" data-iconpos="notext"></a></li>';
});
$('#orders_list').html(output).listview('refresh');
//if paginated, update next button
if (d.meta.next) {
$("#id_ordersNext").attr('href', d.meta.next);
$("#id_ordersNext").show();
} else {
$("#id_ordersNext").hide();
}
if (d.meta.previous) {
$("#id_ordersPrevious").attr('href', d.meta.previous);
$("#id_ordersPrevious").show();
} else {
$("#id_ordersPrevious").hide();
}
$("#id_ordersTotal").html(d.meta.total_count);
$.mobile.loading('hide');
});
});
}
$(function () {
//bind the nav
$(".order_nav").die();
$(".order_nav").live('click', function () {
$(".order_nav").each(function () {
$(this).removeClass('ui-btn-active');
});
$(this).addClass('ui-btn-active');
getOrders($(this).attr('href'));
return false;
});
//bind the view order
$(".view_order").die();
$(".view_order").live('click', function () {
//save var
window.viewOrderReference = $(this).attr('id');
$.mobile.changePage("view_order.html");
});
$("#id_ordersNext,#id_ordersPrevious").die();
$("#id_ordersNext,#id_ordersPrevious").live('click', function () {
getOrders(null, $(this).attr('href'));
return false;
});
//default view
getOrders('Order Placed');
});下面是我为通过JQMobile加载的页面使用的html:
<div data-role="page" data-needs-auth='true'>
<script src="js/list_orders.js"></script>
<div class="headerDiv" data-role='header' data-theme='b'><a href="index.html" data-icon="home">Home</a>
<h1>Jubilee Distributors</h1>
<a href="login.html" class="logged_in" data-icon="home">Login</a></div>
<div data-role='navbar'>
<ul>
<li><a href="Order Placed" class='ui-btn-active order_nav' data-ajax="false">Placed</a></li>
<li><a href="Order Picked" class='order_nav' data-ajax="false">Picked</a></li>
<li><a href="Order Delivered" class='order_nav' data-ajax="false">Delivered</a></li>
</ul>
</div>
<div data-role="content">
<ul data-role='listview' id="orders_list" data-filter="true"><li>No records found</li></ul>
<p><a href='#' id='id_ordersPrevious' style='display:none;' data-role="button" data-icon="arrow-l" data-iconpos="notext" data-inline="true">Previous</a> <span id='id_ordersTotal' class='record-count'></span> records found <a href='#' id='id_ordersNext' style='display:none;' data-role="button" data-icon="arrow-r" data-iconpos="notext" data-inline="true">Previous</a>
</p>
</div>
<div id='footerDiv' data-role="footer"></div>
</div>这一切在桌面上的任何浏览器上都能正常工作,但是当我在Android设备上运行它时,事情就会发生,或者更确切地说,不会发生。
就像我说的,这一切在任何桌面浏览器上都能正常工作,但在Android设备上就不行了。
有什么想法吗?
编辑:修复了第二个问题,但是第一个问题仍然存在。如果我导航到页面,然后离开它,然后再回来,它就能工作了。
发布于 2012-11-29 06:26:21
通过将dom准备函数更改为pageinit来修正此错误。
https://stackoverflow.com/questions/13617091
复制相似问题