JS:实时搜索不适用于两个查询之间的空格

时间:2018-09-12 17:47:30

标签: javascript search

对JSON数据执行此搜索操作,当在搜索栏中输入术语时,它可以显示过滤器数据,但是当我添加空格后,它仅对一个术语起作用,而对其他术语却什么也不显示,我在做什么错?此外,过滤JSON文件中的14000条记录中的数据还需要花费时间

$(document).ready(function() {
        $('#selectterm').change(function() {
            var sterm = $(this).val();
            $.ajax({
                type: "GET",
                url: "/fee/get/" + sterm,
                success: function(res) {
                    if (res) {
                        $('#txt-search').keyup(function() {
                            var searchField = $(this).val();
                            if (searchField === '') {
                                $('#filter-records').html('');
                                return;
                            }
                            var output = '<div class="row">';
                            var count = 1;
                            $.each(res, function(key, lol) {
                                if ((lol.strm.toLowerCase().indexOf(searchField.toLowerCase()) != -1) ||
                                    (lol.subject_cd.toLowerCase().indexOf(searchField.toLowerCase())  != -1) ||
                                    (lol.catalog_nbr.toLowerCase().indexOf(searchField.toLowerCase())  != -1)) {
                                    output += '<table class="table">';
                                    output += '<thead>';
                                    output += '<tr>';
                                    output += '<th scope="col">Term</th>';
                                    output += '<th scope="col">Subject</th>';
                                    output += '<th scope="col">Catlog Nbr</th>';
                                    output += '</tr>';
                                    output += '</thead>';
                                    output += '<tbody>';
                                    output += '<tr>';
                                    output += '<td>' + lol.strm + '</td>';
                                    output += '<td>' + lol.subject_cd + '</td>';
                                    output += '<td>' + lol.catalog_nbr + '</td>';
                                    output += '</tr>';
                                    output += '</tbody>';
                                    output += '</table>';
                                    if (count % 2 == 0) {
                                        output += '</div><div class="row">'
                                    }
                                    count++;
                                }
                            });
                            output += '</div>';
                            $('#filter-records').html(output);
                        });
                    } 
                }
            });
        });
    });

0 个答案:

没有答案