mui.ready(function() { var rows = 20, dataC = { time: "", id: "" }; var pulldownRefresh = function() { setTimeout(function() { onePage(); mui('#pullrefresh').pullRefresh().endPulldownToRefresh(); }, 1000); }, pullupRefresh = function() { setTimeout(function() { morePage(); mui('#pullrefresh').pullRefresh().endPullupToRefresh(); }, 1000); } var oAjax = function(url, dataS, otype, oFun) { mui.ajax(baseUrl + url, { dataType: 'json', type: otype, data: dataS, success: function(res) { if(res.success) { //console.log(JSON.stringify(res)) oFun(res) } } }); }, onePage = function() { document.getElementById("questList").innerHTML="" oAjax("/ajax/question", { "rows": rows },"get", myConList) }, morePage = function() { oAjax("/ajax/question", { "time": dataC.time, "id": dataC.id, "rows": rows },"get", myConList) }, myConList = function(res) { var $info = res.data; if($info.length > 0) { dataC.time = res.data[res.data.length - 1].createTime; dataC.id = res.data[res.data.length - 1].id; for(var i = 0; i < $info.length; i++) { var liStr = document.createElement("li"); liStr.className = "mui-table-view-cell"; liStr.setAttribute("data-id", $info[i].id); document.getElementById("questList").appendChild(liStr); myConHtml($info[i], liStr); } if($info.length > rows) { mui('#pullrefresh').pullRefresh().endPullupToRefresh(false); } } else { mui('#pullrefresh').pullRefresh().endPullupToRefresh(true); return; } }, myConHtml = function(dataStr, liStr) { var baImg = "../images/default-q&a.jpg"; var subs = new Array(); if(dataStr.img) { if(dataStr.img.indexOf(',')) { subs = dataStr.img.split(','); } else { subs[0] = dataStr.img; } baImg = baseUrl + "/data/question"+ subs[0]; } var hd = ""; if(dataStr.replyCount > 0) { hd = '回答 ' + dataStr.replyCount + '' } liStr.className = "mui-table-view-cell"; liStr.innerHTML = '
' + dataStr.title + '
' + '' + hd + '
' + '