简体   繁体   中英

How to display output in javascript

I am using python for backend and javascript for user interface, I have multiple files stored in folder and I want to display that using javascript.

function createRowMultiresult(jobjects) {
   var $div = $('<div class="chat Bot"></div>');
   var $div2 = $('<div class="user-photo"><img src="{% static "Robot.jpg%}" /></div>');
   $div.append($div2);
   var $tbl = $('<table style="width:100%;"></table>');

   if (jobjects.length>1){
     var $tr = $('<tr><td style="padding:5px;">Multiple results Found for 
                 your query. Please search with specific keyword</td> 
                 </tr>');
      $tbl.append($tr);
   }
   for(var x=0; x<jobjects.length;x++){
      var currentobj = jobjects[x];
   if (currentobj.ans.indexOf("/AV") != -1){
      var $tr = $('<tr><td style="padding:5px;"><a href="https://Guide' + 
                currentobj.ans +'" target="_blank" >Click Here 
                Guide</a></td></tr>');
      $tbl.append($tr);
   }
   else if(currentobj.ans.indexOf("/AV") == -1){
      var $tr = $('<tr><td style="padding:5px;">' +(x+1)+'.'+ 
                   currentobj.ans.replace(/[^\w\s]/gi, "<br/>") +'</td> 
                   </tr>');
      $tbl.append($tr);

      if (currentobj.Pic.length>7){
        var $tr = $("<tr><td style='text-align:center;'><img 
                      class='productpic' src='{% static '/Pictures/' %}" + currentobj.Pic +"' /></td></tr>");
      $tbl.append($tr);
      }
   else{

   }

  }
}

Change the conditionng a bit more different. if(condition.indexOf("Guide")>-1) { // do something for Guide Related Data } else if(condition.indexOf("information")>-1){// do something for information Related Data} else if(condition.indexOf("indexing")>-1){// do something for indexing Related Data} else{// no condition met, so do whatever requires here} Your above code fails cause you check if 'AV" exists or not, in first two checks. if "AV" doesnt exist, it makes 1st else if true, and the condition met there. So that is the problem of your code.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM