我必须将从服务器接收到的一些数据显示为像这样的 json 对象
{"rowndx":"0","rows":"25","rowstotal":"100","rowsdata":[
["00","DEVICE001","T0_IHOME","1","***","1","10"],
["01","DEVICE002","NO_DEVICE","1","***","1","10"],
["02","DEVICE003","NO_DEVICE","0","***","1","10"],
.....
在表格中显示收到的数据之前,我想在必要时进行更改,将单位添加到数字或用单词替换数字(例如 0 -> OFF 1-> ON)为此,我在 ajax 选项“成功”中关联“我的编码功能。但是,在这种情况下,“正在加载...”消息始终可见,并且不允许进行其他操作。我将我的重新编码过程移至“完整”ajax 选项,这一次它似乎有效。但我不明白我的错误是什么,我不知道我的程序是否可以工作。这是我的表 ajax 配置
url : "devtbl.json",
mtype : "POST",
datatype : "json",
postData : ......
ajaxGridOptions: {
type : 'post',
contentType: 'application/json',
async : false,
complete : DEVparse_serverdata,
error : function() { alert('Something bad happened. Stopping');},
},
jsonReader : {
root : "tablerows",
page : "currentpage",
total : "totalpages",
records : "totalrecords",
cell : "",
id : "0",
userdata : "userdata",
repeatitems : true
},
和我的编码功能
function DEVparse_serverdata(js , textStatus) {
var jsontablereply = {} ;
var rowsxpage_int = parseInt(UB.rowsxpage.DEVtable) ;
var jsonreply = jQuery.parseJSON(js.responseText) ;
jsontablereply.currentpage = "" + (1 + (parseInt(jsonreply.rowndx) / rowsxpage_int));
jsontablereply.totalpages = "" + parseInt((parseInt(jsonreply.rowstotal) + (rowsxpage_int-1)) / rowsxpage_int) ;
jsontablereply.totalrecords = jsonreply.rowstotal;
jsontablereply.tablerows = [] ;
$.each(jsonreply.rowsdata, function(ndx, row) {
var rowarray = [] ;
rowarray[0] = row[0] ;
rowarray[1] = row[1] ;
rowarray[2] = row[2] ;
rowarray[3] = row[3] ;
rowarray[4] = row[4] ;
switch (row[2]) {
case "NO_DEVICE":
rowarray[5] = "***" ;
break ;
case "T0_IHOME":
rowarray[5] = "T=" + row[5] + "°C" ;
break ;
}
jsontablereply.tablerows[ndx] = rowarray ;
}) ; // each
jQuery("#DEVtbl")[0].addJSONData(jsontablereply);
}
(我是 Jquery 的初学者,我的编码风格很差)