jquery自动完成搜索不排序多个键值对

时间:2014-11-08 07:01:36

标签: jquery json jquery-ui search autocomplete

我正在使用jquery ui自动完成搜索来搜索我的某个项目中的主题。但我有一个问题。我在this js fiddle

中实施的搜索副本

在第一次搜索中,我使用单个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) {} );
            } 
              });

correct search

现在选择应用数学我想打开一个新的链接,这就是我调用的地方我绑定了所有主题,不同的键值对,如链接名称和子代码,但绑定后我出错了搜索结果。 你可以看到下面的图片和

使用键值对进行搜索的代码

 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) {} );
            } });

wrong search

我正在寻找应用数学,但我正在获得电气工程的成果 谁能帮我这个 ?。

1 个答案:

答案 0 :(得分:1)

尝试从源中删除函数包装器,因此您只需传入映射的数据集,如下所示: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
                          }

            }),