AutoComplete jQuery Using JSON data

前端 未结 4 990
醉酒成梦
醉酒成梦 2021-01-18 12:08

Imagine a json file with the following data:

[
    {
        color: \"red\",
        value: \"#f00\"
    },
    {
        color: \"green\",
        value: \"         


        
4条回答
  •  花落未央
    2021-01-18 12:56

    $(function() {
                $("#subject_name").autocomplete({
                        source: function(request, response) {
                            $.ajax({
                                url: "api/listBasicsubject",
                                dataType: "json",
                                type: "POST",
                                data: {
                                    subject_name: request.term,
    
                                },
                                success: function(data) {
                                    response($.map(data.data, function(item) {
                                            return {
                                                label: item.subject_name,
                                                value: item.subject_name
    
                                            }
                                        });
                                    }
    
    
                                },
                                autoFocus: true,
                                minLength: 1
                            });
                        });
                });
    

提交回复
热议问题