我正在尝试使用从文本字段获得的输入来搜索 xml 文件。我能够循环遍历文件并将字符串相互比较,因此如果字符串完全相同,它们基本上匹配。我希望能够仅使用一个单词进行搜索并找到包含该单词的所有结果。
换句话说,如果我搜索“lorem”,我希望它找到“lorem ipsum”。
function searchXML(){
$.get("xml/ResolvedIssues.xml",{},function(xml){
input = document.getElementById("inputSearch").value;
myHTMLOutput = '';
myHTMLOutput += '<h3>Tickets containing "';
myHTMLOutput += input;
myHTMLOutput += '"</h3>'
$('Table1',xml).each(function(i) {
application = $(this).find("Application").text();
module = $(this).find("Module").text();
ticket = $(this).find("Ticket_x0023_").text();
summary = $(this).find("Summary").text();
detail= $(this).find("Details").text();
problem = $(this).find("Problem_Flag").text();
version = $(this).find("Version").text();
build = $(this).find("Build").text();
checked = $(this).find("Checked_In").text();
status = $(this).find("Status").text();
if (input == module || input == ticket || input == summary ||
input == detail || input == problem || input == version ||
input == build || input == checked || input == status) {
$('#demo').html('');
mydata = BuildTable(application, module, ticket, summary, detail, problem, version, build, checked, status);
myHTMLOutput = myHTMLOutput + mydata;
};
});
$("#demo").append(myHTMLOutput);
});
}
最佳答案
不要这样做:
if (input == module || input == ticket || input == summary ||
input == detail || input == problem || input == version ||
input == build || input == checked || input == status) {
试试这个:
if ((module + ticket + summary + detail + problem + version +
build + checked + status).indexOf(input) > -1) {
关于javascript - 搜索 XML 文件,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/35783348/