jQuery UI自动完成刷新数据 [英] jQuery UI autocomplete refresh data

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

问题描述

我使用jQuery ui自动完成功能.

I use jQuery ui autocomplete feature.

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] = ...
}

function addColor(){
    ...
    color[n] = color;
}

当用户输入新颜色时,它将被保存到颜色阵列中.我切换到自动完成表单,但是在刷新页面之前,输入的数据不可用.

When the user enters new color it is saved to the color array. I switch to the autocomplete form but the entered data is not aviable until I refresh the page.

有什么想法可以使新颜色自动完成吗?

Any ideas how to make the new color avialable for autocomplete?

推荐答案

更新颜色时,还需要更新

When you update the color, you need to also update the source that autocomplete uses, like this:

function addColor() {
    //add colors
    $('#empf').autocomplete("option", { source: colors });
}

此处是一个演示示例,添加颜色并一次更新自动填充源第二.

Here's a sample demo doing this, adding a color and updating the autocomplete source once a second.

这篇关于jQuery UI自动完成刷新数据的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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