示例数据
[
{
"messageId": "216",
"message": "{\"message\":\"set archive as processed\"}",
"systemTime": "2016-01-12 06:36:29"
},
{
"messageId": "215",
"message": "{\"message\":\"clear locTab\"}",
"systemTime": "2016-01-12 06:36:29"
}
]
代码
function filterLogs() {
console.log('Filtering logs...');
var vlogID = $('#logID').val();
var vkeyWord = $('#keyWord').val();
var vkeyWord = $('#keyWord').val();
var vfromDate = $('#fromDate').val();
var vtoDate = $('#toDate').val();
$.each(function(i, v) {
if (v.messageId == "215") {
alert(v.message);
return;
}
});
// if (vlogID == '419') {
// alert(message);
// } else {
// // var result = {};
// result.logID = logID;
// result.keyWord = keyWord;
// console.log(JSON.stringify(result));
$.ajax({
type: 'GET',
// url: proxy + '/server/message/list.php?type='
url: 'log.txt',
data: 'logID:vlogID'
})
.done(function(result) {
console.log(result);
var resultCol = 'green';
var resultJson = result;
if (resultJson || resultJson)
if (!JSON.parse(resultJson)) {
alert('error:> ' + JSON.stringify(result));
} else {
activities = JSON.parse(result);
$('#activities').render(activities);
$(document).ready(function() {
$('.message').each(function() {
var input = JSON.parse($(this).text());
// alert($(this).text());
$(this).jsonViewer(input);
});
});
}
})
.fail(function(result) {
alert('fail: ' + resultJson.succes + ' > ' + JSON.stringify(result));
$infoField.html(JSON.stringify(result)).css('color', 'red');
});
console.log('Done Filtering...');
}
$(document).ready(function() {
$('#filterLogs').click(function() {
filterLogs();
})
});
<div class="content">
<div class="container">
<div id="activities">
<div class="col-sm-12">
<div class="panel panel-primary">
<div class="panel-heading">
<h3 id="messageId" class="panel-title"><span> : [ </span><span class="systemTime"></span><span> ] </span></h3>
</div>
<div class="panel-body message">
</div>
</div>
</div>
</div>
</div>
</div>
<ul>
<li class="active">
<input id="logID" type="text" class="form-control" placeholder="Log ID..."></li><a href="#"></a>
</li>
<li>
<input id="keyWord" type="text" class="form-control" placeholder="Keyword..."></li><a href="#"></a></li>
</li>
<li>
<form>
<div class="input-daterange input-group" id="datepicker">
<input id="fromDate" type="text" class="input-sm form-control" name="start" placeholder="From date" />
<span class="input-group-addon">to</span>
<input id="toDate" type="text" class="input-sm form-control" name="end" placeholder="To date"/>
</div>
<li><button id="filterLogs" type="submit" class="btn btn-success " href="/">Filter</button></li>
</form>
<a href="#"></a>
</li>
<li>
</li>
</ul>
感谢您的帮助