Problems and solutions of automatic completion of input box using bootstrap Typeahead

Source: Internet
Author: User

According to the Typeahead use method found on the Internet, there was an error in the last step, the data can be read from the database, but when the input box shows prompt, it is all shown as: underfined. I can't find out where the problem is in half a day. Later on the http://blog.64cm.com/post/2014/08/13/%E4%BD%BF%E7%94%A8bootstrap-typeahead%E6%8F%92%E4%BB%B6 inadvertently found such a sentence: " In the current version of Typeahead, it is no longer supported to call the Ajax method directly in the source property to get the data source. "reminds me, because I am based on the method of the Internet, is to call the Ajax method directly in source.

Back now the ACE demo, although there is no Ajax example, but there are comments to explain how to use, but the use of English (digression: To do technical understanding of English is really important. ), after a turn debugging, finally can display correctly. The post code is as follows:

JS Code

<script type= "Text/javascript" >JQuery (function($) {                //Typeahead.js        //example taken from plugin ' s page at:https://twitter.github.io/typeahead.js/examples/        varSubstringmatcher =function() {//Substringmatcher () method            return functionFindmatches (query, process) {//query is equipped with the keyword, PROCESSJ is the value returned                varmatches, Substringregex; varparams = {"token": GetStorage ("token"), "flag": 0, "name": Query}; varParameter_str= "";  for(varKeyinchparams) {Parameter_str+ = "&" +key+ "=" +Params[key]; }                      varFullurl=getoption ("gykj_host") + "Institution/list?" +getoption ("Gykj_callbackparam") + "=" +getoption ("Gykj_callbackfunc") +Parameter_str; $("#submenu_info"). HTML (fullurl); $.ajax ({url:fullurl, type:' Get ', DataType:"Jsonp", Jsonp:getoption ("Gykj_callbackparam"), Jsonpcallback:getoption ("Gykj_callbackfunc"), Async:false, Error:function() {alert ("List:" +getoption ("Connectionerrormessage")); }, Success:function(data) {//$ ("#submenu_info"). HTML (fullurl);                            if(data.code==0){                                varArr,substringregex; Arr=[]; Substrregex=NewREGEXP (query);//this must be, or it will be shown as underfined                                     for(varIteminchdata.data) {                                        varStr=Data.data[item].name; if(Substrregex.test (str)) {//The typeahead JQuery plugin expects suggestions to a                                            //JavaScript object, refer to Typeahead docs for more infoArr.push ({value:str}); }} process (                                                                ARR); }                        }                    })                             }        }         $(' Input.typeahead '). Typeahead ({hint:true, highlight:true, MinLength:1}, {name:' States ', Displaykey:' Value ', Source:substringmatcher ()//the current version of the Source property cannot call the Ajax method directly to get the data source, via the Substringmatcher () method                     }); });</script>

Html

<!--inline scripts related to this page -<Scriptsrc=".. /assets/js/ace-elements.js "></Script><Scriptsrc=".. /assets/js/typeahead.jquery.js "></Script><inputtype= "text"ID= "Name"placeholder= "Institution name"class= "col-xs-10 col-sm-5 typeahead scrollable"value=""AutoComplete= "Off" />

Problems and solutions of automatic completion of input box using bootstrap Typeahead

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.