自动填充脚本在JSON中返回id

时间:2012-11-16 22:39:22

标签: jquery autocomplete

我在我的文本框中使用自动完成功能。我希望检索到我的json的ID应该存储在隐藏的文本框中id =“special”保存为逗号分隔。假设我在autosuggestion中选择了什么值,它的id应该存储在以逗号分隔的隐藏文本框中。 如何最小化这段代码。我是jquery的新手。

$(".artist").focus().autocomplete( '<?php echo HTTP_PATH . '/artists/getArtistList'; ?>', {
            multiple: true,
            mustMatch: true,
            matchContains: true,
            scroll: true,
            minChars: 0,
            autoFill: true,
            dataType: "json",
            parse: function(data) {
                return $.map(data, function(item) {
                    return { data: item, value: item.name, result: item.name};
                });
            },
            formatItem: function(item) {
                return item.name;
            },
            formatResult: function(item) {
                return item.id;
            },
            formatMatch: function(item) {
                return item.name;
            } 
        });

1 个答案:

答案 0 :(得分:3)

您使用的是jQuery UI还是使用其他插件?如果您使用的是jQuery UI,那么您可以参考http://jqueryui.com/autocomplete/#remote-jsonp