开发者

Javascript array for auto-complete

I implemented a auto-complete function that takes an array as parameter.

$(document).ready(function(){
    $('#empf').autocomplete(['black', 'white', 'red']);
}

Now I do not want a static array. Outside the document ready function I declared a function that retrieves the colors from local storage. I call this function in document ready function.

So everytime the user enters new input I want to put it in the array and use that array globally. Is that possible?

For initialisation of the array, at any point I know the number of colores stored.

So instead of the static array I put a variable e.g. data and I declare data as an array. I tried it this way:

var colors;

$(document).ready(function(){
        loadColors();
        $('#empf').autocomplete(colors);
}

function loadColors(){
 colors = new Array(getNumColor()));
//in a loop save the colors to array using colors[i] = ...
}

But this causes my application to cr开发者_如何学编程ash. Any ideas?

Any ideas?


Like Rahul said this seems to be an issue of parenthesis. With firebug(another link) it is easier to detect/debug these bugs.

Also I think you should use jquery ui's autocomplete if you are not already using it(I am not sure if you are using it).


Seems to be an issue with parenthesis.

It should be

colors = new Array(getNumColor());

instead of

colors = new Array(getNumColor()));
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜