簡體   English   中英

jQuery自動完成搜索不對多個鍵值對進行排序

[英]jquery autocomplete search not sorting for multiple key value pairs

我正在使用jQuery ui自動完成搜索來搜索我的項目之一中的主題。 但是我有一個問題。 我在此js小提琴中實現的搜索副本

在第一次搜索中,我使用的是沒有任何鍵值對的單個json數組對象,這就是為什么我在自動完成搜索中獲得正確結果的原因,請參見下圖,

僅包含主題的數組的代碼

 var responseArray =["Electrical Machines II-2009","6- Sigma Management -2012", "Advanced Computer Architecture-2012","Advanced Controlled  drives -2011","Advanced Mechanics of Solids-2010","Analog & Digital Circuits-2009","Analog Communication-2012", "Antenna & Wave Propagation-2010","Applied Mathematics I-2012", "Applied Operational Research-2012",    "Applied Sciences - II (Physics & Chemistry)-2012","Applied Thermodynamics-2008","Artificial Intelligence -2010","Automata Language and Computation-2009"];  
 $("#search-correct").autocomplete({
            source:   responseArray,
            minLength: 1,
            search :  function(event,ui){   
            $( "#search-bar" ).on( "autocompletesearch", function( event,ui) {} );
            } 
              });

正確搜索

現在,在選擇應用數學時,我想打開一個新鏈接,這就是為什么我要在哪里調用將所有具有不同鍵值對(例如鏈接名和子代碼)的主題進行綁定的原因,但是在綁定之后,我在搜索時得到了錯誤的結果。 您可以在下面看到圖片,

鍵值對搜索代碼

 var responseArray1=[{"fullName":" Electrical Machines II-2009","paperLink":"http://domain.in/examLibrary/EE4/2009/DEC/ee4-2009-dec-ee4.4.pdf","sub_code":"EE4-4","yr":"2009"},{"fullName":"6- Sigma Management -2012","paperLink":"http://domain.in/examLibrary/ME7/2012/MAY/me7-2012-may-me7.4f.pdf\n","sub_code":"ME7-4F","yr":"2012"},{"fullName":"Analog & Digital Circuits-2009","paperLink":"http://domain.in/examLibrary/IT3/2009/DEC/it3-2009-dec-it3.3.pdf","sub_code":"IT3-3","yr":"2009"},{"fullName":"Analog Communication-2012","paperLink":"http://domain.in/examLibrary/ETC5/2012/MAY/etc5-2012-may-etc5.3.pdf\n","sub_code":"ETC5-3","yr":"2012"},{"fullName":"Antenna & Wave Propagation-2010","paperLink":"http://domain.in/examLibrary/ETC6/2010/MAY/etc6-2010-may-etc6.4.pdf\n","sub_code":"ETC6-4","yr":"2010"},{"fullName":"Applied Operational Research-2010","paperLink":"http://domain.in/examLibrary/ME7/2010/DEC/me7-2010-dec-me7.5f.pdf","sub_code":"ME7-5F","yr":"2010"},{"fullName":"Artificial Intelligence -2013","paperLink":"http://domain.in/examLibrary/CO6/2013/MAY/co6-2013-may-co6.3.pdf\n","sub_code":"CO6-3","yr":"2013"},{"fullName":"Automata Language and Computation-2013","paperLink":"http://domain.in/examLibrary/CO5/2013/MAY/co5-2013-may-co5.2.pdf\n","sub_code":"CO5-2","yr":"2013"},{"fullName":"Biomedical Instrumentation-2012","paperLink":"http://domain.in/examLibrary/EE8/2012/MAY/ee8-2012-may-ee8.4d.pdf\n","sub_code":"EE8-8D","yr":"2012"}]
 $("#search-bar").autocomplete({ 
          source: function (request, response) {  
                  response($.map(responseArray, function(item) {
                  return {
                            label: item.fullName,
                            value: item.fullName,
                            linkValue : item.paperLink,
                            sub_code  : item.sub_code,
                            yr: item.yr
                          }
              }));
            },
            minLength: 1,
            search :  function(event,ui){
              $( "#search-bar" ).on( "autocompletesearch", function( event,ui) {} );
            } });

錯誤的搜尋

我在哪里尋找應用數學,但我正在獲得電氣工程的結果,有人可以幫助我嗎?

嘗試從源代碼中刪除函數包裝器,因此您只是傳入映射的數據集,如此處所示: http : //jsfiddle.net/no3taLbv/2/

          source: $.map(responseArray1, function(item)                 {
                  return {
                            label: item.fullName,
                            value: item.fullName,
                            linkValue : item.paperLink,
                            sub_code  : item.sub_code,
                            yr: item.yr
                          }

            }),

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM