0
で働いていません。JavaScriptのカスタム検索機能は、こんにちは、私はJSON配列</p> <p>私のコードは、クロムとfirfoxではなく、IEで正常に動作のためのカスタム検索を作成しようとしていますIE
コードは次のように動作します。それは各検索用語「針」を通ってループし、質問内の単語を見つけたらそれを配列に追加します。同じ質問で別の検索語句が見つかった場合は、ヒットカウンタが増加します。
すべてのコードはここにあり、実行することができます。
私が手にエラーがある:
Line:24
Char:3
Error:qna_questions[..].q is null or not an object
qna_questions = [
{ 'q':'this is a very good question','id':'1'},
{ 'q':'i like pllo in the summer','id':'2'},
{ 'q':'it rains allot in the summer mushroom','id':'3'},
{ 'q':'i love people and straberry cake','id':'4'},
{ 'q':'i love people and berry rain','id':'5'},
{ 'q':'dsff sd fsd rains sdfsd fsd ','id':'6'},
{ 'q':'the dog is fat','id':'7'},
];
var search_result = new Array();
var needle = "dog fat summer allot mushroom";
var needle = needle.split(' ');
for(j = 0; j < qna_questions.length; j++) {
for(i =0; i < needle.length; i++) {
if(qna_questions[j].q.search(needle[i].toLowerCase()) != -1) {
if(search_result[qna_questions[j].id] === undefined) {
search_result[qna_questions[j].id] = {
'q':qna_questions[j].q,
'id':qna_questions[j].id,
'hits':0
};
} else {
search_result[qna_questions[j].id].hits++;
}
}
}
}
search_result.sort(function(a,b) { return parseInt(b.hits) - parseInt(a.hits) });
for (x in search_result)
{
alert(search_result[x].q + ": "+search_result[x].hits +"<br />");
}