在我下面的代碼片段試圖添加對,我知道會出來,這樣,如果它發現它,它返回一個查詢,我需要運行到屏幕上的行每行比較其他功能如何使用Javascript推送多個數組並從函數中返回它們?
error: there were errors found during runtime 12.0
warning: incorrect info 1.0
warning: file at 'C://localhost/myfiles' not found 0.0
warning: file at 'C://localhost/css' not found 0.0
warning: file at 'C://localhost/js' not found 0.0
warning: file at 'C://localhost/assets' not found 5615612.0
這是我試圖做的,但我不知道如何忽略數字,以便實際上可以比較線條。 所有這些都發生在第一部分運行之後,我得到的數字大於0.0。
含義這些行獲得比較:
錯誤:有運行過程中發現12.0
警告錯誤:不正確信息1.0
警告:文件在 'C://本地主機/資產' 未找到5615612.0
,這些都是我的條件:
if ("error: there were errors found during runtime 12.0" == line){
//run this query for database runtimeDB
}
if("warning: incorrect info 1.0" == line){
//this query
//+1 for incorrectInfoDB
}
if("warning: file at 'C://localhost/myfiles' not found 0.0" == line){
//this query
//+1 for incorrectInfoDB
}
if("warning: file at 'C://localhost/css' not found 0.0" == line){
//this query
//+1 for outerfilesDB
}
if("warning: file at 'C://localhost/css' not found 0.0" == line){
//this query
//+1 for outerfilesDB
}
if("warning: file at 'C://localhost/js' not found 0.0" == line){
//this query
//+1 for outerfilesDB
}
if("warning: file at 'C://localhost/assets' not found 0.0" == line){
//this query
//+1 for outerfilesDB
}
什麼我以爲是使用getLines()函數,然後從該函數返回沒有最後一個數字的字符串,以便進行比較。
function trim_numbers($string) {
$numbers = strrchr($string, ' ');
return str_replace($numbers, '', $string);
}
的問題是,我不知道如何把陣列,讓他們都在同一個getLines()函數和我沒有寫更多相同的代碼。這意味着在打開了該功能
function getLines() {
var text = $('textarea').val();
var lines = text.split("\n");
var requiredLines = [];
var runtimeDB = [];
var incorrectInfoDB = [];
var outerfilesDB = [];
lines.forEach(function(line) {
number = line.match(/\d+\.\d+$/);
if (number != null && number[0] > 0){
requiredLines.push(line);
if (trim_numbers(line) == "error: there were errors found during runtime"){
//run this query for database runtimeDB
//push this query to be outputed
}
if("warning: incorrect info 1.0" == line){
//this query for it database array
//push this query to be outputed
}
}
});
return requiredLines;
}
添加的陣列爲每個數據庫組
- runtimeDB
- incorrectInfoDB
- outerfilesDB
我不知道,如果我正確地解釋了邏輯 但是
- 第一它得到大於0.0
- 則它陣列推到數據庫組從值大於0.0
也較高,有一種方法,以優化我的邏輯更高的所有的值?
function getLines() {
var text = $('textarea').val();
var lines = text.split("\n");
var requiredLines = [];
lines.forEach(function(line) {
number = line.match(/\d+\.\d+$/);
if (number != null && number[0] > 0)
requiredLines.push(line);
});
return requiredLines;
}
$(document).ready(
function() {
$('#printlogs').html(getLines().join('<br>'));
});
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<textarea style="width:100%;height:120px">
error: there were errors found during runtime 12.0
warning: incorrect info 1.0
warning: file at 'C://localhost/myfiles' not found 0.0
warning: file at 'C://localhost/css' not found 0.0
warning: file at 'C://localhost/js' not found 0.0
warning: file at 'C://localhost/assets' not found 5615612.0
</textarea>
<h4>Error Log</h4>
<printlogs id="printlogs" style="color:red"></printlogs>
<br>
<p>after these logs I want to get the arrays of each group that has their own database queries for the ones printed in printlogs</p>
<p>
ex.
</p>
<h4>runtimeDB</h4>
<p>
//run this query for this line
</p>
<h4>incorrectInfoDB</h4>
<p>
//run this query for this line<br> //run this other query for other line ...
</p>
我是否明白所有你想要的是解析最後沒有編號的行,所以直到'找到',以便你可以將它們與你的條件進行比較? – deg
是的,我想比較那些值大於0.0的值與我自己的行(沒有數字)的預定列表以及該行所屬的查詢。 – learningbyexample
你寫這個日誌嗎?如你所說,你是否能夠輸出與目前不同的內容? – deg