sergiodlopes / jquery-flexdatalist

Flexible input autocomplete/datalist plugin for jQuery
http://projects.sergiodinislopes.pt/flexdatalist/
MIT License
364 stars 84 forks source link

Support dotted notation #195

Closed sylvainblot closed 3 years ago

sylvainblot commented 5 years ago

I found myself in a situation where the data returned by the Ajax call are in a nested structure. This MR allow the dotted notation such as:

$(function (){
    $('.flexdatalist').flexdatalist({
        searchContain: true,
        //textProperty: 'properties.label',
        textProperty: '{properties.id}, {properties.label.name}',
        searchIn: ['properties.label'],
        valueProperty: 'properties.id',
        minLength: 3,
        searchDisabled: false,
        focusFirstResult: true,
        selectionRequired: true,
        resultsProperty: 'features',
        noResultsText: "Aucune adresse trouvée",
        visibleProperties: ["properties.label","properties.id"],
        url: 'http://localhost:7878/search',
        keywordParamName: 'q'
    });
});

Example of AJAX response:

{
    "type": "FeatureCollection",
    "version": "draft",
    "features": [{
        "type": "Feature",
        "geometry": {
            "type": "Point",
            "coordinates": [3.065202, 50.636836]
        },
        "properties": {
            "label": "1 Rue Pierre Mauroy 59800 Lille",
            "score": 0.8568090909090909,
            "housenumber": "1",
            "citycode": "59350",
            "context": "59, Nord, Hauts-de-France (Nord-Pas-de-Calais)",
            "postcode": "59800",
            "name": "1 Rue Pierre Mauroy",
            "id": "ADRNIVX_0000000268010175",
            "y": 7059987.9,
            "importance": 0.4249,
            "alias": "rue de paris",
            "type": "housenumber",
            "city": "Lille",
            "x": 704620.5,
            "street": "Rue Pierre Mauroy"
        }
    } [...]
    ],
    "attribution": "BAN",
    "licence": "ODbL 1.0",
    "query": "1 rue pierre",
    "limit": 5
}
sergiodlopes commented 3 years ago

Thank you for your PR.

I've implemented your function in a more integrated way across all plugin so that it can be used on more options.

Sérgio