数据格式化
前端界面接受到的数据都是string类型的,当以date传输到前端的时候,是以millionsecond为单位,可以进行如下操作对数据进行格式化
{title: "开始时间", field: "beginTime",align: 'center',formatter:TimeFormat},
{title: "结束时间", field: "endTime",align: 'center',formatter:TimeFormat},
function TimeFormat(value){
var date = new Date(value);
// var format = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
return date.toLocaleString();
}
Date.prototype.toLocaleString = function() {
return this.getFullYear() + "-" + (this.getMonth() + 1) + "-" + this.getDate() + " " + this.getHours() + ":" + this.getMinutes() + ":" + this.getSeconds();
};
通过重写toLocaleString来对日期进行格式化
数据的判断显示
{title: "任务状态", field: "state",align: 'center',formatter:status},
function status(value){
if(value==1){
return '<font color="red">有异常</font>';
}else if(value == 0){
return '<font color="black">进行中</font>';
}else if(value == 2)
return '<font color="green">已完成</font>';
};
对于thymleaf的get拼接请求
使用框架的前端界面,会出现转义的问题,为了 避免这种不必要的转移,可以添加 标签date,如下
function operateFormatter(value, row, index) {
if(row.state == "1"){
return [
'<a class="exception" href="javascript:void(0);">',
'<i class="glyphicon glyphicon-signal"></i>查看异常信息',
'</a>'
].join('');
}
else{
return [
].join('');
}
}
window.operateEvents = {
'click .like': function (e, value, row, index) {
connectTest(row.gisNodeUrl, index, true);
},
'click .exception':function (e, value, row, index){
var _iframe = window.parent;
/* <![CDATA[ */
_iframe.showInfoLayer("/job/pathException?id="+row.taskId+"&nodeIp="+row.ip,"异常信息", "1100px", "600px");
/* ]]> */
},
};