转自:http://blog.csdn.net/cdefg198/article/details/8115336
好像新版的Jquery UI,autoComplete的options里面没有max,不知道是不是我没有知道,如果数据量很大,有可能显示非常。所以修改了一下代码,定死了,没有添加到options里面去。
在Jquery-ui.js的6659行代码处,_normalize函数里面。
原来是:
- _normalize: function ( items ) {
- // assume all items have the right format when the first item is complete
- if ( items.length && items[0].label && items[0].value ) {
- return items;
- }
- return $.map( items, function ( item ) {
- if ( typeof item === "string" ) {
- return {
- label: item,
- value: item
- };
- }
- return $.extend({
- label: item.label || item.value,
- value: item.value || item.label
- }, item );
- });
- },
修改为:
- _normalize: function ( items ) {
- // assume all items have the right format when the first item is complete
- if ( items.length && items[0].label && items[0].value ) {
- return items;
- }
- var i=0;
- return $.map( items, function ( item ) {
- if (i >= 20 )
- return ;
- i++;
- if ( typeof item === "string" ) {
- return {
- label: item,
- value: item
- };
- }
- return $.extend({
- label: item.label || item.value,
- value: item.value || item.label
- }, item );
- });
- },
最大显示20条