且构网

分享程序员开发的那些事...
且构网 - 分享程序员编程开发的那些事

jQuery的搜索JSON和填充表单字段

更新时间:2023-09-20 22:47:40

在网络各地的行...有点拖网和我能够这一个梳理,感谢的 http://www.jensbits.com/ 所有现在的工作。

OK ... a bit more trawling around the web and I was able to sort this one out, thanks to http://www.jensbits.com/ All working now.

$("#state").autocomplete({
            source: function( request, response ) {
            $.ajax({
                url: "location.json",
                dataType: "json",
                data: {term: request.term},
                success: function(data) {
                            response($.map(data, function(item) {
                            return {
                                label: item.state,
                                id: item.id,
                                abbrev: item.abbrev
                                };
                        }));
                    }
                });
            },
            minLength: 2,
            select: function(event, ui) {
                $('#state_id').val(ui.item.id);
                $('#abbrev').val(ui.item.abbrev);
            }
        });