The Bootstrap learning series uses the Bootstrap Typeahead component to implement the Baidu drop-down effect, bootstraptypeahead

Source: Internet
Author: User

The Bootstrap learning series uses the Bootstrap Typeahead component to implement the Baidu drop-down effect, bootstraptypeahead

UnderScore Official Website: http://underscorejs.org/

Reference: http://www.css88.com/doc/underscore/

Page code:

@{ViewBag.Title = "Index";}<script src="Scripts/bootstrap-typeahead.js"></script><script src="Scripts/underscore-min.js"></script><div>

Easy to use

<div style="margin: 10px 50px"><label for="product_search">Product Search:</label><input id="product_search" type="text" data-provide="typeahead" data-source='["DATA1", "DATA2", "DATA3"]' /></div>

Use scripts to fill data

<Div style = "margin: 10px 50px"> <label for = "product_search"> Product Search: </label> <input id = "product_search_js" type = "text" data-provide = "typeahead"> </div> <script type = "text/javascript"> $ (document ). ready (function ($) {$. fn. typeahead. constructor. prototype. blur = function () {var that = this; setTimeout (function () {that. hide ()}, 250) ;}; $ ('# product_search_js '). typeahead ({source: function (query, process) {return ["JS data 1", "JS data 2", "JS data 3"] ;}, highlighter: function (item) {return "=>" + item + "<=";}, updater: function (item) {console. log ("'" + item + "' selected. "); // the browser console outputs $ (" # product_search "). val (item); return item ;}}) ;}) </script>

Support for Ajax Data Retrieval

<div style="margin: 10px 50px"><label for="product_search">Product Search:</label><input id="product_search_ajax" type="text" data-provide="typeahead"></div><script type="text/javascript">$('#product_search_ajax').typeahead({source: function (query, process) {var parameter = { query: query };$.post('@Url.Action("AjaxService")', parameter, function (data) {process(data);});}});</script>

Use object data

<div style="margin: 10px 50px"><label for="product_search">Product Search:</label><input id="product_search_object" type="text" data-provide="typeahead"></div><script type="text/javascript">$(function () {var products = [{id: 0,name: "object1",price: 499.98},{id: 1,name: "object2",price: 134.99},{id: 2,name: "object3",price: 49.95}];$('#product_search_object').typeahead({source: function (query, process) {var results = _.map(products, function (product) {return product.name;});process(results);},highlighter: function (item) {return "==>" + item + "<==";},updater: function (item) {console.log("'" + item + "' selected.");return item;}});});</script></div> 

Controller

public ActionResult Index(){return View();}public ActionResult AjaxService(){string query = "";if (!string.IsNullOrWhiteSpace(Request["Query"]))query = Request["Query"].ToString();var data = ("AJAX1,AJAX2,AJAX3").Split(',');return Json(data);} 

As shown below:

Next we will continue to introduce the BootStrap Typeahead component of the Bootstrap Learning Series to achieve the Baidu pull-down effect (continued)

The above section describes how to use the Bootstrap Typeahead component in the Bootstrap Learning Series to implement the Baidu drop-down effect. I hope it will help you. If you have any questions, please leave a message, the editor will reply to you in a timely manner. Thank you very much for your support for the help House website!

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.