値が配列に存在するかどうかをテストするための調査を行っており、indexOf('textvalue') の一致を取得し続けています。
しかし、私の「テキスト値」は部分文字列になるため、一致するものはありません。これは、フィールド名をメソッドに渡しているためで、「Door: Front Left;」を削除する必要があるだけです。"Door" の配列項目に一致するテキスト。これを達成する方法を知っている人はいますか?
私が取り組んでいるサンプルコードは次のとおりです。
(spnSelectedDisclosures には、選択されたフィールドのリストが含まれます。これは、セミコロンで区切られたテキストから前のフィールド選択を削除するコードです。)
var currentText = $("#spnSelectedDisclosures").text();
var existingArr = currentText.split(";")
for (i=0;i < existingArr.length;i++) {
var indexItem = " " + existingArr[i].toString(); // why is this still an object, instead of a string? Adding a space to it was a desperate try to make indexItem a string variable.
if (indexItem.contains(substringText)) { // offending line, saying the object has no method 'contains'
alert("there's been a match at: " + i);
textToRemoveIndex = i;
break;
}
}
var textToRemove = existingArr[textToRemoveIndex];
var newText = currentText.replace(textToRemove,"");
$("#spnSelectedDisclosures").text(newText);