Result Search not found

0

Good morning!

I have two JS, one that emulates something like a database following the example:

var menu;

$(document).ready(function() {


menu = new clsMenu();

var Exemplo01 = menu.addFolder("Exemplo", "Exemplo")    

})

And another that filters it:

    function letras(texto) {
        var letrasPorString = [];
        var letrasPorIndex = [];
        var i, letra;

        for (i = 0; i < texto.length; i++) {
            letra = texto.substr(i, 1);
            if (letrasPorString[letra] === undefined) {
                letrasPorString[letra] = 1;
                letrasPorIndex.push(letra);
            } else {
                letrasPorString[letra]++;
            }
        };

        this.porString = letrasPorString;
        this.porIndex = letrasPorIndex;
    }

    function compararLetras(letrasObj1, letrasObj2, corte) {
        var i;
        var qndeCertas = 0;
        for (i = 0; i < letrasObj1.porIndex.length; i++) {
            var letra = letrasObj1.porIndex[i];
            if (letrasObj1.porString[letra] === letrasObj2.porString[letra]) {
                qndeCertas++;
            }
        };

        var percentual = (qndeCertas / letrasObj1.porIndex.length) * 100;
        return percentual >= corte;
    }

    function duplas(texto) {
        var tduplas = [];
        var i;
        for (i = 0; i < texto.length - 1; i++) {
            tduplas.push( texto.substr(i, 2) );
        }

        return tduplas;
    };

    function compararDuplas(duplas1, duplas2, corte) {
        var i, j;
        var encontrados = 0;
        for (i = 0; i < duplas1.length; i++) {
            var dupla = duplas1[i];
            var encontrado = false;
            for (j = 0; j < duplas2.length; j++) {
                if (dupla == duplas2[j]) {
                    encontrado = true;
                }
            };

            if (encontrado) { encontrados++ }
        };

        var percentual = (encontrados / duplas1.length) * 100;
        return percentual >= corte
    }

    function compararKeyTag(key, tag, buscaAproximada, corte) {
        if (buscaAproximada === true) {
            var lk, lt, dk, dt;
            lk = new letras(key);
            lt = new letras(tag);
            dk = new duplas(key);
            dt = new duplas(key);

            if (corte === undefined) { corte = 70 }
            if ( compararLetras(lk, lt, corte) && compararDuplas(dk, dt, corte) ) {
                return true;
            } else {
                return false;
            }
        } else {
            if (tag.indexOf(key) > -1) {
                return true;
            } else {
                return false;
            }
        }
    }

    function compararKeysTags(keysArr, tagsArr, buscaAproximada, corte) {
        var encontrados = 0;
        $(keysArr).each(function(index, key) {
            var encontrado = false;
            $(tagsArr).each(function(index, tag) {
                if (compararKeyTag( key, tag, buscaAproximada, corte )) {
                    encontrado = true;;
                }
            });

            if (encontrado) {encontrados++};
        });

        if ( encontrados == keysArr.length ) { 
            return true;
        } else {
            return false;
        }
    }

Always return the result of this filter on a div in the html file:

            <h1 style="margin-top: -10%;">
                <b>
                    MENU
                </b>
            </h1>

            <form class="search-container example">
                <input type="text" id="search-input" placeholder="Busca" style="color: black">

                <button type="submit" id="search"><i class="glyphicon glyphicon-search"></i></button>
            </form>

            <div id="menu">

            </div>  
The problem is, I got this project already developed, and the person who created it today is no longer working next to me, other than I still do not have a knowledge to the point where I can do what I need, that is, when the search does not return result, a message like "Your search did not match" is displayed.

Could anyone help me with this?

Thank you very much!

    
asked by anonymous 25.09.2018 / 15:23

1 answer

0

What function is called when the search button is clicked? Just go to this function that is active when you click on the search button and make when the search return is null, that it is activated a window.alert("Resultado Busca não localizada"); .

    
25.09.2018 / 16:09