const MAX_LENGTH = 30;
google.charts.load('current', {'packages':['table']});
google.charts.setOnLoadCallback(drawTable);
function drawTable() {
var data = new google.visualization.DataTable();
data.addColumn('string', 'Server IP');
data.addColumn('string', 'Exception');
data.addColumn('boolean', 'Critical');
var logData = [];
logData.push(formatRow(1, '10.0.0.1', longExp, false));
logData.push(formatRow(2, '10.0.0.2', longExp, true));
logData.push(formatRow(3, '10.0.0.2', longExp, false));
logData.push(formatRow(4, '10.0.0.3', 'Short exception', true));
logData.push(formatRow(5, '10.0.0.3', longExp, false));
data.addRows(logData);
var table = new google.visualization.Table(document.getElementById('table_div'));
table.draw(data, {showRowNumber: true, width: '100%', height: '100%', allowHtml: true});
}
var longExp = 'java.io.IOException: Cannot run program "/home/Work/jre1.6.0_45/bin/java": error=13, Permission denied\n \t at\n java.lang.ProcessBuilder.start(ProcessBuilder.java:1048)\n \t at java.lang.Runtime.exec(Runtime.java:620)\n \t at\njava.lang.Runtime.exec(Runtime.java:528)\n \t at org.eclipse.debug.core.DebugPlugin.exec(DebugPlugin.java:879)\n \t at org.eclipse.jdt.launching.AbstractVMRunner.exec(AbstractVMRunner.java:91)\n \t at org.eclipse.jdt.internal.launching.StandardVMRunner.run(StandardVMRunner.java:413)\n org.eclipse.jdt.internal.launching.environments.Analyzer.analyze(Analyzer.java:41)';
function formatRow(id, ip, err_msg, criticity){
if(err_msg.length > MAX_LENGTH){
err_msg = err_msg.substring(0, MAX_LENGTH) + "…";
err_msg += '<a href="#" onclick="javascript:show(' + id + ')">[more]</a>';
}
return [ip, err_msg, criticity];
}
function show(id){
//TODO: get complete message from id
alert(longExp);
}
<script type="text/javascript" src="https://www.gstatic.com/charts/loader.js"></script>
<div id="table_div"></div>
請提供一個代碼示例或jsfiddle。沒辦法知道你在爲這篇文章工作。 – Twisty