ITeye博客

Jquery UI autoComplete 设置max

wangrl · 2012-11-11 20:01 · 企业应用 · Web前端 · Markdown

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

 

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

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

原来是:

[javascript] view plain copy

  1. _normalize:  function ( items ) {
  2. // assume all items have the right format when the first item is complete
  3. if  ( items.length && items[0].label && items[0].value ) {
  4. return  items;
  5. }
  6. return  $.map( items,  function ( item ) {
  7. if  (  typeof  item ===  "string"  ) {
  8. return  {
  9. label: item,
  10. value: item
  11. };
  12. }
  13. return  $.extend({
  14. label: item.label || item.value,
  15. value: item.value || item.label
  16. }, item );
  17. });
  18. },

修改为:

[javascript] view plain copy

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

最大显示20条

评论(0)

暂无评论。

评论功能维护中,当前仅展示历史评论。