Adding JQuery Autocomplete in Symfony2 Entity field

后端 未结 3 1094
小蘑菇
小蘑菇 2020-12-05 16:29

I have a city and voters entity in a one to many relationships.I want to convert the entity field(thousands of records in a dropdown) to a text input so that I can implement

3条回答
  •  渐次进展
    2020-12-05 16:56

    Here a solution to add a field regarding the response given by the Symfony Controller. In success, add fields you want by returning a object. Then, in the select, you can access it by ui.item.fields

    $('#mySelector').autocomplete({
    
            source : function(requete, reponse) {
    
                lettre = {
                    lettre: $('#lettre').val()
                };
    
                $.ajax({
                    url: Routing.generate('chargementSource'),
                    dataType: 'json',
                    data : lettre,
                    success: function (donnee) {
                        
                        reponse(
                                $.map(donnee, function (objet) {
                                    return { 
                                      value: '' + objet.nom + ' ' + objet.prenom +', '+ objet.adresse +' '+ objet.codepostal +', '+ objet.ville + '', 
                                     id: objet.id 
                                   }
                                })
                        );
    
                    }
    
                });
            },
            select: function (event, ui) {
    
                $('#myId').val(ui.item.id);
                //alert(ui.item.id);
                //$('#myId').val(ui.elem.value);
    
                return false;
    
            }
    
        });

提交回复
热议问题