javascript - Hide "null" result -
i've working searching function embedded html website search informations on sharepoint site. working when have result without "description", result show "null". so, want hide null value :) , don't know how can that.
here function search/result :
<script> function searchlistener(text){ var count = 0; $(".result").empty(); var queryget = "my url"; $.ajax({ url: queryget, method: "get", headers: { "accept": "application/json; odata=verbose" }, success: onquerysuccess, error: onqueryerror }); function onquerysuccess(data) { var results = data.d.query.primaryqueryresult.relevantresults.table.rows.results; var title,url, index, id, desc; console.log(results); $.each(results, function () { $.each(this.cells.results, function () { if(this.key == "title"){ title = this.value; } if(this.key == "path"){ url = this.value; } if(this.key == "description"){ desc = this.value; } }); count = count +1; if(((url.indexof('qt') !== -1) || (url.indexof('news') !== -1) || (url.indexof('tuto') !== -1) || (url.indexof('service_data') !== -1)) && (url.indexof('dispform') !== -1)){ if(url.indexof('qt') !== -1) index ="quicktraining"; if(url.indexof('tuto') !== -1) index ="tuto"; if(url.indexof('news') !== -1) index ="news"; if(url.indexof('service_data') !== -1) index ="service"; id = url.split('id=')[1]; $(".result").append("<div class='bullet'><a class='searchlink' id='"+ id +" "+ index + "' href='#'><h2>" + title +"</h2></a><h4 id='desc'>" + desc + "</h4></div>"); } }); } function onqueryerror(error) { if($(".form-control").val().length != 0){ $(".result").append("<h5>no results found</h5>"); $(".result").show(); }else{ $(".result").hide(); } } } </script>
an idea ? many thanks!
$.each(this.cells.results, function () { if(this.key == "title"){ title = this.value; } if(this.key == "path"){ url = this.value; } if(this.key == "description") { if(this.value != " ") { desc = this.value; } else { desc = ""; } } });
hope work you...
Comments
Post a Comment