首页 诗词 字典 板报 句子 名言 友答 励志 学校 网站地图
当前位置: 首页 > 教程频道 > 网站开发 > Web前端 >

Jquery UI autoComplete 设立max

2012-11-23 
Jquery UI autoComplete 设置max转自:http://blog.csdn.net/cdefg198/article/details/8115336?好像新版的

Jquery UI autoComplete 设置max

转自:http://blog.csdn.net/cdefg198/article/details/8115336

?

好像新版的Jquery UI,autoComplete的options里面没有max,不知道是不是我没有知道,如果数据量很大,有可能显示非常。所以修改了一下代码,定死了,没有添加到options里面去。

在Jquery-ui.js的6659行代码处,_normalize函数里面。

原来是:

[javascript] view plaincopy
  1. _normalize:?function(?items?)?{??????????//?assume?all?items?have?the?right?format?when?the?first?item?is?complete??
  2. ????????if?(?items.length?&&?items[0].label?&&?items[0].value?)?{??????????????return?items;??
  3. ????????}??????????return?$.map(?items,?function(?item?)?{??
  4. ????????????if?(?typeof?item?===?"string"?)?{??????????????????return?{??
  5. ????????????????????label:?item,??????????????????????value:?item??
  6. ????????????????};??????????????}??
  7. ????????????return?$.extend({??????????????????label:?item.label?||?item.value,??
  8. ????????????????value:?item.value?||?item.label??????????????},?item?);??
  9. ????????});??????},??


修改为:

[javascript] view plaincopy
  1. _normalize:?function(?items?)?{??????????//?assume?all?items?have?the?right?format?when?the?first?item?is?complete??
  2. ????????if?(?items.length?&&?items[0].label?&&?items[0].value?)?{??????????????return?items;??
  3. ????????}??????????var?i=0;??
  4. ????????return?$.map(?items,?function(?item?)?{??????????????if(i?>=?20?)??
  5. ????????????????return;??????????????i++;??
  6. ????????????if?(?typeof?item?===?"string"?)?{??????????????????return?{??
  7. ????????????????????label:?item,??????????????????????value:?item??
  8. ????????????????};??????????????}??
  9. ????????????return?$.extend({??????????????????label:?item.label?||?item.value,??
  10. ????????????????value:?item.value?||?item.label??????????????},?item?);??
  11. ????????});??????},??


最大显示20条

热点排行