Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
144 views
in Technique[技术] by (71.8m points)

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(/[^ws]/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{

   }

  }
}
See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)

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.


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...