在处理jQuery的自动完成没有结果 [英] Handling no results in jquery autocomplete

查看:125
本文介绍了在处理jQuery的自动完成没有结果的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

嘿,我想如果没有结果,为用户当前查询返回的消息!我知道我需要进军keyup事件,但它看起来像插件使用它

Hey I'm trying to return a message when there are no results for the users current query! i know i need to tap into the keyup event, but it looks like the plugin is using it

推荐答案

您可以尝试提供一个解析选项(函数来处理数据解析),做你需要的时候没有返回结果进行解析。

You could try supplying a parse option (function to handle data parsing) and do what you need when no results are returned to parse.

此示例假设您正在找回包含全名和地址属性JSON对象的数组。

This example assumes you're getting back an array of JSON objects that contain FullName and Address attributes.

   $('#search').autocomplete( {
       dataType: "json",
       parse: function(data) {
         var array = new Array();
         if (!data || data.length == 0) {
             // handle no data case specially
         }
         else {
            for (var i = 0; i < data.length; ++i) {
               var datum = data[i];
               array[array.length] = { 
                                       data: datum,
                                       value: data.FullName + ' ' + data.Address,
                                       result: data.DisplayName
                                     };
            }
         }
         return array;
       }
   });

这篇关于在处理jQuery的自动完成没有结果的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆