Skip to content

Issue from multi level deep data inside source objects #281

@GDM70

Description

@GDM70

I've got a dataset which is an array of objects, something like this :

{"waarden2":[{"klant":{"t118achternaam":"Verberck , ... },"patient":{"t120naam":"Aiko", ...}},{"klant":{"t118achternaam":"Ibens", ...},"patient":{"t120naam":"Aiko", ... }}]}

My code

$.typeahead({
        input: "#l01b",
        order: "asc",
        maxItem: 50,
        minLength: 3,
        cancelButton: false,
        dynamic: true,
        display: ["patient.t120naam", 
                    "patient.t120ras",
                    "patient.t120ras2",
                    "patient.t120identificatie",
                    "patient.t120paspoort",
                    "patient.t120opmerking",
                    "patient.t120anafylaxie",
                    "patient.t120soort",
                    "klant.t118achternaam",
                    "klant.t118straat",
                    "klant.t118postcode",
                    "klant.t118gemeente"],
        template: function () {
            return "{{patient.t120naam}}" + " " + "{{klant.t118achternaam}}" + ",  " + "{{patient.t120ras}}" + "<br/>" + "{{klant.t118straat}}" + " " + "{{klant.t118huisnummer}}" + ",  " + "{{klant.t118postcode}}" + " " + "{{klant.t118kenletters}}" + " " + "{{klant.t118gemeente}}";
        },
        emptyTemplate: "geen resultaten gevonden voor {{query}}",
        source: {
            klanten: {
                ajax: function (query) {
                    return {
                        type: "GET",
                        path: "waarden2",
                        url: "/vf/rest/patienten/T120_05?",
                        data: {
                            q: query
                        }
                    };
                }
            }
        },
        callback: {
            onResult: function (node, query, result, resultCount) { 
                if (resultCount === 1) {
                    vm.input_l01a = result[0]; 
                    vm.resultCount_l01a = resultCount;
                }
            },
            onNavigateBefore: function (node, query, event) {
                if (event.keyCode === 13 && vm.resultCount_l01a === 1) {
                    vm.findPatient(vm.input_l01a.patient.t120klantid, vm.input_l01a.patient.t120patientid);
                    $("[tabindex=2]").focus();
                }
            },
            onNavigateAfter: function (node, lis, a, item, query, event) {
                if (~[38,40].indexOf(event.keyCode)) {
                    var resultList = node.closest("form").find("ul.typeahead__list"),
                        activeLi = lis.filter("li.active"),
                        offsetTop = activeLi[0] && activeLi[0].offsetTop - (resultList.height() / 2) || 0;
                    resultList.scrollTop(offsetTop);
                }
            },
            onClickAfter: function (node, a, item, event, data) {
                vm.input_l01a = item;
                $("[tabindex=2]").focus();
                vm.findPatient(item.patient.t120klantid, item.patient.t120patientid);
            }
        }
    });

everything works fine untill i select a line, then i get the error :

Uncaught TypeError: Cannot read property 'toString' of undefined
at HTMLLIElement. (jquery.typeahead.js:1852)
at HTMLLIElement.dispatch (jquery-2.1.0.min.js:3)
at HTMLLIElement.r.handle (jquery-2.1.0.min.js:3)

Can't figure it out how to fix this issue :-(

Metadata

Metadata

Assignees

No one assigned

    Labels

    Projects

    No projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions