jquery - How can I use Twitter Typeahead with SignalR to get autocomplete suggestions -



jquery - How can I use Twitter Typeahead with SignalR to get autocomplete suggestions -

the client-side javascript below doesn't work, code completes before cb gets populated. populating cb in signalr done function fails late because phone call asynchronous.

how can populate source using signalr in response user input typeahead textbox?

var tonamesource = function (query, cb) { settimeout(function () { var prefix = $('#toname').val(); var mycbval = []; talk.server.getpcont(prefix, connectionid) .done(function (mmid) { $.each(mmid, function () { var myobj = this; mycbval.push({ name: myobj.name, id: myobj.id }); }); }).fail(function (error) { // }); cb(mycbval); }, 300) }; $(".tt-toname").typeahead(null, { minlength: 2, source: tonamesource, displaykey: 'name', }).on('typeahead:selected', function (obj, datum) { //$(".tt-name").typeahead('val', datum.name).typeahead('close'); });

happily found trigger typeahead event programmatically using jquery gave me reply analogy. signalr can populate twitter typeahead suggestions.

the reply in case in setting source see below. learned calling callback function can - , must - done within of done or fail segments run when phone call signalr server async return. , callback method produces display of suggestions.

<div class="typeahead-wrapper"> <input class="tt-toname" id="toname" name="toname" type="text" placeholder="enter name" /> </div>

(recommend skip update next section!)

$(".tt-toname").typeahead(null, { minlength: 2, // begin source source: function (query, process) { var prefix = $('#toname').val(); var mycbval = [];// callback value // "talk" = $.connection.talkhub; , set elsewhere globally //getpcont custom signalr method on server talk.server.getpcont(prefix, connectionid) .done(function (mmid) { $.each(mmid, function () { var myobj = this; mycbval.push({ name: myobj.name, id: myobj.id }); process(mycbval);//process callback method }); }).fail(function (error) { process([]);//process callback method, don't know if necessary here, produce no suggestions }); } // end source , displaykey: 'name', }).on('typeahead:selected', function (obj, datum) { //$(".tt-name").typeahead('val', datum.name).typeahead('close'); });

updated sept 11, 2015 work typeahead.js version 0.11.1 ------------------------

$(".tt-toname").typeahead({ // hint: true, //highlight: true, minlength: 2 } , { name: 'myname', limit:10, source: function (q, sync, async) { talk.server.getcontacts(q, connectionid) .done(function (data, status) { async(data); } ).fail(function (error) { alert("in fail" + error); }); }, displaykey: 'name' });

also see: bootstrap typeahead not showing hints expected

jquery asp.net-mvc signalr twitter-typeahead

Comments

Popular posts from this blog

java Multi query from Mysql using netbeans -

c# - DotNetZip fails with "stream does not support seek operations" -

c++ - StartServiceCtrlDispatcher don't can access 1063 error -