How to render JSON response using latest typeahead.js library

后端 未结 1 881
鱼传尺愫
鱼传尺愫 2021-02-09 00:55

I have got a search box in my application where in users can search for a patient details stored in the database. they would type in the name of the patient and server will resp

相关标签:
1条回答
  • 2021-02-09 01:09

    Your current code is too simple to achieve that, you need to use template and remote to achieve that:

    $('#search-box').typeahead([{                              
        name: 'Search',
        valueKey: 'forename',
        remote: {
            url: 'searchPatient.do?q=%QUERY',
            filter: function (parsedResponse) {
                // parsedResponse is the array returned from your backend
                console.log(parsedResponse);
    
                // do whatever processing you need here
                return parsedResponse;
            }
        },                                             
        template: [                                                                 
            '<p class="name">{{forename}} {{surname}} ({{gender}} {{age}})</p>',
            '<p class="dob">{{dateOfBirth}}</p>'
        ].join(''),                                                                 
        engine: Hogan // download and include http://twitter.github.io/hogan.js/                                                               
    }]);
    

    Just to give you the basic idea, hope it helps.

    0 讨论(0)
提交回复
热议问题