Result Search not located

Asked

Viewed 32 times

0

Good morning!

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

var menu;

$(document).ready(function() {


menu = new clsMenu();

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

})

And another that makes the filter on 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 in 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 took this project already developed, and the person who created it today is no longer working with me, outside I still do not have a knowledge to the point to be able to do what I need, which is, when the search does not return result, be presented a message like "Your search was unsuccessful".

Someone could help me with that?

Thank you very much!

1 answer

0


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

Browser other questions tagged

You are not signed in. Login or sign up in order to post.