jQuery自动完成搜索不对多个键值对进行排序

安基塔

我正在使用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) {} );
            } });

错误的搜寻

我在哪里寻找应用数学,但我正在获得电气工程的结果,有人可以帮助我吗?

林肯·安德森(Lincoln Anderson)

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

            }),

本文收集自互联网,转载请注明来源。

如有侵权,请联系 [email protected] 删除。

编辑于
0

我来说两句

0 条评论
登录 后参与评论

相关文章