我剛剛爲我的問題創建了一個基本用例,在那裏我卡住了,我將有searchStr
關鍵字數組對象從客戶端,我會檢查是否所有的搜索關鍵字只與行相比匹配results
。與下面的代碼,它總是返回空數組results
,如何解決這個問題或任何更好的方式來實現這個任務?如果所有關鍵字匹配,如何將值推到數組中?
search.js
var line = "ticketNumber:45287,Lorem Ipsum is simply dummy text of the printing and typesetting industry. Lorem Ipsum has been the industry's standard dummy text ever since the 1500s, when an unknown printer "
var searchStr = [{
"text": "45287"
}, {
"text": "standard"
}]
var results = [];
function matchSearchStr(line, searchStrArray) {
for (var i = 0; i < searchStrArray.length; i++) {
if (line.toLowerCase().indexOf(searchStrArray[i].toLowerCase()) != -1) {
results.push({
filename: "file",
value: line
});
console.log(results);
}
}
}
matchSearchStr(line, searchStr)
不寫'searchStr = [「45287」,「standard」]''的任何理由? –
我使用的角度'ngInputTags'在輸入關鍵字時創建數組對象 – hussain
不相關,但不是使用全局變量,而是在搜索函數內部創建'results'並返回它。 –