Skip to content

ericpanorel/bootstrap-typeahead-knockout-binding

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

4 Commits
 
 
 
 

Repository files navigation

bootstrap-typeahead-knockout-binding

KnockoutJS Binding handler for Bootstrap TypeAhead plugin

Sample Usage

HTML View

```
Enter your text
```

Javascript View Model & Code

``` (function (ko, $) { "use strict"; var my = my || {};
        //ViewModel
        my.vm = (function () {
            var YourText = ko.observable(),
                Suggestions = function (searchTerm, callback) {


                    $.ajax({
                        type: "POST",
                        url: '/api/search',
                        data: { Term: searchTerm },
                        dataType: 'json',
                        success: function (data) {

                            callback(data);
                        },
                        error: function () {
                            callback(['']);

                        }
                    });

                };

            return {
                Suggestions: Suggestions,
                YourText: YourText
            }

        })();


        // document ready
        $(document).ready(function () {
            ko.applyBindings(my.vm);
        });


    })(ko, jQuery);
<p>ASP .Net API Controller.</p>

using System; using System.Collections.Generic; using System.Linq; using System.Net; using System.Net.Http; using System.Web.Http;

namespace MvcApplication1.Controllers { public class SearchParam { public string Term { get; set; } } public class SearchController : ApiController { public IEnumerable Post(SearchParam data) { // Assemble your data here
return new string[] {"John","Mark","Joseph" }; } } }

<p>Note: This works with other back-end technologies too, like PhP, classic ASP, etc...</p>

About

KnockoutJS Binding handler for Bootstrap TypeAhead plugin

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published