我是Jquery Mobile的新手,目前我正在使用Jquery在'table using reflow'中动态加载数据时遇到问题。问题是只显示一个标题列,即使我调用$(table).refresh()。首先,我使用Jquery Mobile 1.3.1然后更改为JQuery Mobile 1.4.5但问题未解决。最初,我在html中添加表格thead只是为了检查这是否是问题,然后我把它加载到javascript下面是HTML代码::
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8" />
<meta name="format-detection" content="telephone=no" />
<meta name="msapplication-tap-highlight" content="no" />
<!-- WARNING: for iOS 7, remove the width=device-width and height=device-height attributes. See https://issues.apache.org/jira/browse/CB-4323 -->
<meta name="viewport" content="user-scalable=no, initial-scale=1, maximum-scale=1, minimum-scale=1, width=device-width, height=device-height, target-densitydpi=device-dpi" />
<link rel="stylesheet" href="css/custom.css"/>
<link rel="stylesheet" href="css/jquery.mobile-1.4.5.min.css"/>
<script src="js/jquery-2.0.3.min.js"></script>
<script src="js/jquery.mobile-1.4.5.min.js"></script>
</head>
<body>
<!-- Start of first page -->
<div data-role="page" id="login-form">
<div data-role="header">
<h1>Header1</h1>
</div>
<div id="div-content" name="div-content" role="main" class="ui-content">
<form id="div-content-form" name="div-content-form" action="index.html">
<div data-role="fieldcontain">
<label for="applicantNos">Applicant Nos:</label>
<input type="text" id="applicantNos" name="applicantNos" required="required" />
</div>
<div data-role="fieldcontain">
<label for="idNos">ID Nos:</label>
<input type="text" id="idNos" name="idNos" required="required" />
</div>
<input type="button" value="Submit" class="button" />
</form>
</div>
<div data-role="footer"></div>
</div>
<!-- Start of second page -->
<div data-role="page" id="application-status" data-add-back-btn="true">
<div data-role="header">
<h4>Application Status</h4>
</div>
<div id="application-status-content" name="application-status-content" role="main" class="ui-content">
<table data-role="table" id="app-status-table" data-mode="reflow" class="ui-responsive table-stroke">
<thead>
</thead>
<tbody></tbody>
</table>
</div>
<div data-role="footer"></div>
</div>
<script src="cordova.js"></script>
<script src="js/index.js"></script>
<script type="text/javascript">
app.initialize();
</script>
</body>
Javascript代码:
var app = {
initialize: function() {
this.bindEvents();
},
// Bind Event Listeners
//
// Bind any events that are required on startup. Common events are:
// 'load', 'deviceready', 'offline', and 'online'.
bindEvents: function() {
document.addEventListener('deviceready', this.onDeviceReady, false);
},
// deviceready Event Handler
//
// The scope of 'this' is the event. In order to call the 'receivedEvent'
// function, we must explicitly call 'app.receivedEvent(...);'
onDeviceReady: function() {
$(document).ready(function () {
$('.button').click(function() {
event.preventDefault();
var applicantNos = $('#applicantNos').val().trim();
var idNos = $('#idNos').val().trim();
if (applicantNos != '' && idNos != '') {
$.ajax({
url: "http://localhost:8083/fetchDetails",
type: "POST",
data: {
applicantNos : applicantNos,
idNos: idNos
}
})
.done(function(responseData){
$.mobile.changePage("#application-status", {
respData: responseData,
transition: "flip"
});
})
.fail(function(msg) {
alert(msg.responseText);
});
}
});
$(document).on("pagebeforechange", function (e, data) {
if (data.toPage[0].id == "application-status") {
showAppStatusData(data.options.respData);
}
});
function showAppStatusData(data) {
var pageData = data;
var tHead = $('table#app-status-table thead');
tHead.append($("<tr><th data-priority='1'>Application No.</th>"));
tHead.append($("<th data-priority='2'>Column 2</th>"));
tHead.append($("<th data-priority='3'>Column 3</th>"));
tHead.append($("<th data-priority='4'>Column 4</th>"));
tHead.append($("<th data-priority='5'>Column 5</th>"));
tHead.append($("<th data-priority='6'>Column 6</th>"));
tHead.append($("<th data-priority='7'>Column 7</th>"));
tHead.append($("<th data-priority='8'>Column 8</th>"));
tHead.append($("<th data-priority='9'>Column 9</th></tr>"));
var tBody = $('#app-status-table tbody');
tBody.append($("<tr><td>" + data.applicationNos + "</td>"));
tBody.append($("<td>" + data.column2 + "</td>"));
tBody.append($("<td>" + data.column3 + "</td>"));
tBody.append($("<td>" + data.column4 + "</td>"));
tBody.append($("<td>" + data.column5 + "</td>"));
tBody.append($("<td>" + data.column6 + "</td>"));
tBody.append($("<td>" + data.column7 + "</td>"));
tBody.append($("<td>" + data.column8 + "</td>"));
tBody.append($("<td>" + data.column9 + "</td></tr>"));
// $("#app-status-table").append(tHead).append(tBody);
$("#app-status-table").table("refresh");
//tHead.closest("table#app-status-table").table("refresh").trigger("create");
//tBody.closest("table#app-status-table").table("refresh").trigger("create");
}
});
}
};
附加纹波仿真器快照,该快照仅显示第一列标题,Body完全显示。即使我在HTML代码中添加了表'thead',但这也行不通!
此问题与此链接有关: https://github.com/jquery/jquery-mobile/pull/6007/files
请提供解决方案以解决因为我花了整整1天的时间。 感谢
答案 0 :(得分:3)
问题是你试图追加jQuery对象:
tHead.append($("<tr><th data-priority='1'>Application No.</th>"));
因此jQuery会自动关闭第一个标题列上的<TR>
标记。
而是将整个行构建为字符串,然后在结尾追加一次:
function showAppStatusData(data) {
var pageData = data;
var tHead = $('table#app-status-table thead');
var headRow = "<tr><th data-priority='1'>Application No</th>";
headRow += "<th data-priority='2'>Column 2</th>";
headRow += "<th data-priority='3'>Column 3</th>";
headRow += "<th data-priority='4'>Column 4</th>";
headRow += "<th data-priority='5'>Column 5</th>";
headRow += "<th data-priority='6'>Column 6</th>";
headRow += "<th data-priority='7'>Column 7</th>";
headRow += "<th data-priority='8'>Column 8</th>";
headRow += "<th data-priority='9'>Column 9</th></tr>";
tHead.append(headRow);
var tBody = $('#app-status-table tbody');
var theRow = "<tr><td>" + data.applicationNos + "</td>";
theRow += "<td>" + data.column2 + "</td>";
theRow += "<td>" + data.column2 + "</td>";
theRow += "<td>" + data.column2 + "</td>";
theRow += "<td>" + data.column2 + "</td>";
theRow += "<td>" + data.column2 + "</td>";
theRow += "<td>" + data.column2 + "</td>";
theRow += "<td>" + data.column2 + "</td>";
theRow += "<td>" + data.column2 + "</td></tr>";
tBody.append(theRow);
$("#app-status-table").table("refresh");
}
<强> DEMO 强>
答案 1 :(得分:0)
对我有用的是将以下内容放在html文件中:
<style>
table { width:100%; }
</style>