I would like to ask the front end, ah, query questions.

is like this, the company needs to take a fake page html to show it, which has the query function of the table, how should I write the query, as shown below.

   $(function(){
    var dataTable = [
        {"batteryCode":"S16030116","battreyV":"107","circleLine":"75%",
        "batteryType":"","showTime":"2018-3-12","dealTime":"2018-4-12",
        "operator":"","resul":"V14","dealLate":""},
        {"batteryCode":"S16030116","battreyV":"107","circleLine":"75%",
        "batteryType":"","showTime":"2018-3-12","dealTime":"2018-4-12",
        "operator":"","resul":"V14","dealLate":""},
        {"batteryCode":"S16030116","battreyV":"107","circleLine":"75%",
        "batteryType":"","showTime":"2018-3-12","dealTime":"2018-4-12",
        "operator":"","resul":"V14","dealLate":""},
        {"batteryCode":"S16030116","battreyV":"107","circleLine":"75%",
        "batteryType":"","showTime":"2018-3-12","dealTime":"2018-4-12",
        "operator":"","resul":"V14","dealLate":""}
    ];


     var str = "";
     str += "<tbody">";
        for (var i = 0; i < dataTable.length;iPP){
            str += "<tr>";   
            str+="<td>"+dataTable[i].batteryCode+"</td>";
            str+="<td>"+dataTable[i].battreyV+"</td>"
            str+="<td>"+dataTable[i].circleLine+"</td>"
            str+="<td>"+dataTable[i].batteryType+"</td>"
            str+="<td>"+dataTable[i].showTime+"</td>"
            str+="<td>"+dataTable[i].dealTime+"</td>"
            str+="<td>"+dataTable[i].operator+"</td>"
            str+="<td>"+dataTable[i].resul+"</td>"
            str+="<td>"+dataTable[i].dealLate+"</td>"
            str += "</tr>";
        }
    str += "</tbody>";
    $(".inner_tab").append(str)


    })

Jun.16,2021

Fuzzy search?
or what? Describe the requirements in detail
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>Document</title>
<style>
tr>td{
    padding: 5px 10px;
}    
</style>
</head>
<body>
<input type="text" class="searchText">
<button class="getSearch"></button>
<div class="inner_tab">
    
</div>
<script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/3.3.1/jquery.min.js"></script>
<script>

        var dataTable = [
            {'batteryCode':'S16030116','battreyV':'107','circleLine':'75%',
            'batteryType':'','showTime':'2018-3-12','dealTime':'2018-4-12',
            'operator':'','resul':'V14','dealLate':''},
            {'batteryCode':'S16030116','battreyV':'107','circleLine':'75%',
            'batteryType':'','showTime':'2018-3-12','dealTime':'2018-4-12',
            'operator':'','resul':'V14','dealLate':''},
            {'batteryCode':'S16030116','battreyV':'107','circleLine':'75%',
            'batteryType':'','showTime':'2018-3-12','dealTime':'2018-4-12',
            'operator':'','resul':'V14','dealLate':''},
            {'batteryCode':'S16030116','battreyV':'107','circleLine':'75%',
            'batteryType':'','showTime':'2018-3-12','dealTime':'2018-4-12',
            'operator':'','resul':'V14','dealLate':''}
        ];

        
        $('.getSearch').click(function(){
            $('table').remove()
            let msg = $('.searchText').val()
            let searchTarget = []
            dataTable.map(e=>{
                if(e.batteryCode == msg){
                    searchTarget.push(e)
                }
            })
            let str = "";
            str += "<table>";
                for (var i = 0; i < searchTarget.length;iPP){
                    str += "<tr>";   
                    str+="<td>"+dataTable[i].batteryCode+"</td>";
                    str+="<td>"+dataTable[i].battreyV+"</td>"
                    str+="<td>"+dataTable[i].circleLine+"</td>"
                    str+="<td>"+dataTable[i].batteryType+"</td>"
                    str+="<td>"+dataTable[i].showTime+"</td>"
                    str+="<td>"+dataTable[i].dealTime+"</td>"
                    str+="<td>"+dataTable[i].operator+"</td>"
                    str+="<td>"+dataTable[i].resul+"</td>"
                    str+="<td>"+dataTable[i].dealLate+"</td>"
                    str += "</tr>";
                }
            str += "</table>";
            $('.inner_tab').append(str)
        })

        


    
</script>
</body>
</html>

dataTable.filter(item => {  
    return item.operator.indexOf('')>-1;
})

//`operator`


since your table has been generated, the $("table tr"). Html () string vaguely matches, the lines that do not match are display:none


clipboard.png

)
Menu