2013-07-31 85 views
0

所以我想填充使用bootstrap typeahead的國家列表。我希望這個人開始在他們居住的國家的文本字段中輸入內容,然後顯示可供選擇的選項。Twitter Bootstrap Typeahead只填充字母「a」

最初,我將數據源設置爲一個變量,這是一個龐大的字符串國家陣列。 當我單獨輸入「a」時,我只得到一個單數「a」。字面上只有字母a。

然後我改變了源直接持有數組本身,數組被保存在兩個單引號內。現在當我打它與結果出現任何按鍵,但字面上當我把「一」的文本框中,結果是: 一個 一個 一個 一個 一個 一個 一個 一個 一個 一個 或類似的東西......它的奇怪。這裏是我的代碼:

在這裏我是JSP裏面的「頭」的部分:

<head> 
    <meta name="viewport" content="width=device-width, initial-scale=1.0"> 
    <title>Disti Tool Wireframe</title> 
    <script type="text/javascript" src="${pageContext.request.contextPath}/js/disti.js"></script> 
    <link rel="stylesheet" href="${pageContext.request.contextPath}/css/style.css" /> 
    <link rel="stylesheet" href="${pageContext.request.contextPath}/css/styling.css" /> 
    <link href="css/bootstrap.min.css" rel="stylesheet" media="screen"> 
    <link rel="stylesheet" href="${pageContext.request.contextPath}/bootstrap/css/bootstrap-responsive.css" /> 

</head> 

這裏是代碼的身體:

<div id = "label">Country:</div> 
<div id ="txtentry"> 
    <input type="text" id="country" data-provide="typeahead" autocomplete="off" class="span3" data-source='["Afghanistan", "Akrotiri", "Albania", "Algeria", "American Samoa", 
    "Andorra", 
    "Angola", 
    "Anguilla", 
    "Antarctica", 
    "Antigua and Barbuda", 
    "Argentina", 
    "Armenia", 
    "Aruba", 
    "Ashmore and Cartier Islands", 
    "Australia", 
    "Austria", 
    "Azerbaijan", 
    "Bahamas, The", 
    "Bahrain", 
    "Bangladesh" 
    "Barbados" 
    "Bassas da India", 
    "Belarus", 
    "Belgium", 
    "Belize", 
    "Benin", 
    "Bermuda", 
    "Bhutan", 
    "Bolivia", 
    "Bosnia and Herzegovina", 
    "Botswana", 
    "Bouvet Island", 
    "Brazil", 
    "British Indian Ocean Territory", 
    "British Virgin Islands", 
    "Brunei", 
    "Bulgaria", 
    "Burkina Faso", 
    "Burma", 
    "Burundi", 
    "Cambodia", 
    "Cameroon", 
    "Canada", 
    "Cape Verde", 
    "Cayman Islands", 
    "Central African Republic", 
    "Chad", 
    "Chile", 
    "China", 
    "Christmas Island", 
    "Clipperton Island", 
    "Cocos (Keeling) Islands", 
    "Colombia", 
    "Comoros", 
    "Congo, Democratic Republic of the", 
    "Congo, Republic of the", 
    "Cook Islands", 
    "Coral Sea Islands", 
    "Costa Rica", 
    "Croatia", 
    "Cuba", 
    "Cyprus", 
    "Czech Republic", 
    "Denmark", 
    "Dhekelia", 
    "Djibouti", 
    "Dominica", 
    "Dominican Republic", 
    "Ecuador", 
    "Egypt", 
    "El Salvador", 
    "Equatorial Guinea", 
    "Eritrea", 
    "Estonia", 
    "Ethiopia", 
    "Europa Island", 
    "Falkland Islands (Islas Malvinas)", 
    "Faroe Islands", 
    "Fiji", 
    "Finland", 
    "France", 
    "French Guiana", 
    "French Polynesia", 
    "French Southern and Antarctic Lands", 
    "Gabon", 
    "Gambia, The", 
    "Gaza Strip", 
    "Georgia", 
    "Germany", 
    "Ghana", 
    "Gibraltar", 
    "Glorioso Islands", 
    "Greece", 
    "Greenland", 
    "Grenada", 
    "Guadeloupe", 
    "Guam", 
    "Guatemala", 
    "Guernsey", 
    "Guinea", 
    "Guinea-Bissau", 
    "Guyana", 
    "Haiti", 
    "Heard Island and McDonald Islands", 
    "Holy See (Vatican City)", 
    "Honduras", 
    "Hong Kong", 
    "Hungary", 
    "Iceland", 
    "India", 
    "Indonesia", 
    "Iran", 
    "Iraq", 
    "Ireland", 
    "Isle of Man", 
    "Israel", 
    "Italy", 
    "Jamaica", 
    "Jan Mayen", 
    "Japan", 
    "Jersey", 
    "Jordan", 
    "Juan de Nova Island", 
    "Kazakhstan", 
    "Kenya", 
    "Kiribati", 
    "Korea, North", 
    "Korea, South", 
    "Kuwait", 
    "Kyrgyzstan", 
    "Laos", 
    "Latvia", 
    "Lebanon", 
    "Lesotho", 
    "Liberia", 
    "Libya", 
    "Liechtenstein", 
    "Lithuania", 
    "Luxembourg", 
    "Macau", 
    "Macedonia", 
    "Madagascar", 
    "Malawi", 
    "Malaysia", 
    "Maldives", 
    "Mali", 
    "Malta", 
    "Marshall Islands", 
    "Martinique", 
    "Mauritania", 
    "Mauritius", 
    "Mayotte", 
    "Mexico", 
    "Micronesia, Federated States of", 
    "Moldova", 
    "Monaco", 
    "Mongolia", 
    "Montserrat", 
    "Morocco", 
    "Mozambique", 
    "Namibia", 
    "Nauru", 
    "Navassa Island", 
    "Nepal", 
    "Netherlands", 
    "Netherlands Antilles", 
    "New Caledonia", 
    "New Zealand", 
    "Nicaragua", 
    "Niger", 
    "Nigeria", 
    "Niue", 
    "Norfolk Island", 
    "Northern Mariana Islands", 
    "Norway", 
    "Oman", 
    "Pakistan", 
    "Palau", 
    "Panama", 
    "Papua New Guinea", 
    "Paracel Islands", 
    "Paraguay", 
    "Peru", 
    "Philippines", 
    "Pitcairn Islands", 
    "Poland", 
    "Portugal", 
    "Puerto Rico", 
    "Qatar", 
    "Reunion", 
    "Romania", 
    "Russia", 
    "Rwanda", 
    "Saint Helena", 
    "Saint Kitts and Nevis", 
    "Saint Lucia", 
    "Saint Pierre and Miquelon", 
    "Saint Vincent and the Grenadines", 
    "Samoa", 
    "San Marino", 
    "Sao Tome and Principe", 
    "Saudi Arabia", 
    "Senegal", 
    "Serbia and Montenegro", 
    "Seychelles", 
    "Sierra Leone", 
    "Singapore", 
    "Slovakia", 
    "Slovenia", 
    "Solomon Islands", 
    "Somalia", 
    "South Africa", 
    "South Georgia and the South Sandwich Islands", 
    "Spain", 
    "Spratly Islands", 
    "Sri Lanka", 
    "Sudan", 
    "Suriname", 
    "Svalbard", 
    "Swaziland", 
    "Sweden", 
    "Switzerland", 
    "Syria", 
    "Taiwan", 
    "Tajikistan", 
    "Tanzania", 
    "Thailand", 
    "Timor-Leste", 
    "Togo", 
    "Tokelau", 
    "Tonga", 
    "Trinidad and Tobago", 
    "Tromelin Island", 
    "Tunisia", 
    "Turkey", 
    "Turkmenistan", 
    "Turks and Caicos Islands", 
    "Tuvalu", 
    "Uganda", 
    "Ukraine", 
    "United Arab Emirates", 
    "United Kingdom", 
    "United States", 
    "Uruguay", 
    "Uzbekistan", 
    "Vanuatu", 
    "Venezuela", 
    "Vietnam", 
    "Virgin Islands", 
    "Wake Island", 
    "Wallis and Futuna", 
    "West Bank", 
    "Western Sahara", 
    "Yemen", 
    "Zambia", 
    "Zimbabwe" ]'> 
</div> 

,這裏是什麼在我的代碼的底部。我在這裏搞了兩次這個數組,因爲我正在搞這個,並試圖看看如何讓它工作。我顯然知道有兩次陣列是多餘的。我只是在調試。

<script src="http://code.jquery.com/jquery.js"></script> 
     <script src="js/bootstrap.min.js"></script> 
     <script type="text/javascript"> 

      var location = ["Afghanistan", "Akrotiri", "Albania", "Algeria", "American Samoa", 
      "Andorra", 
      "Angola", 
      "Anguilla", 
      "Antarctica", 
      "Antigua and Barbuda", 
      "Argentina", 
      "Armenia", 
      "Aruba", 
      "Ashmore and Cartier Islands", 
      "Australia", 
      "Austria", 
      "Azerbaijan", 
      "Bahamas, The", 
      "Bahrain", 
      "Bangladesh" 
      "Barbados" 
      "Bassas da India", 
      "Belarus", 
      "Belgium", 
      "Belize", 
      "Benin", 
      "Bermuda", 
      "Bhutan", 
      "Bolivia", 
      "Bosnia and Herzegovina", 
      "Botswana", 
      "Bouvet Island", 
      "Brazil", 
      "British Indian Ocean Territory", 
      "British Virgin Islands", 
      "Brunei", 
      "Bulgaria", 
      "Burkina Faso", 
      "Burma", 
      "Burundi", 
      "Cambodia", 
      "Cameroon", 
      "Canada", 
      "Cape Verde", 
      "Cayman Islands", 
      "Central African Republic", 
      "Chad", 
      "Chile", 
      "China", 
      "Christmas Island", 
      "Clipperton Island", 
      "Cocos (Keeling) Islands", 
      "Colombia", 
      "Comoros", 
      "Congo, Democratic Republic of the", 
      "Congo, Republic of the", 
      "Cook Islands", 
      "Coral Sea Islands", 
      "Costa Rica", 
      "Cote d'Ivoire", 
      "Croatia", 
      "Cuba", 
      "Cyprus", 
      "Czech Republic", 
      "Denmark", 
      "Dhekelia", 
      "Djibouti", 
      "Dominica", 
      "Dominican Republic", 
      "Ecuador", 
      "Egypt", 
      "El Salvador", 
      "Equatorial Guinea", 
      "Eritrea", 
      "Estonia", 
      "Ethiopia", 
      "Europa Island", 
      "Falkland Islands (Islas Malvinas)", 
      "Faroe Islands", 
      "Fiji", 
      "Finland", 
      "France", 
      "French Guiana", 
      "French Polynesia", 
      "French Southern and Antarctic Lands", 
      "Gabon", 
      "Gambia, The", 
      "Gaza Strip", 
      "Georgia", 
      "Germany", 
      "Ghana", 
      "Gibraltar", 
      "Glorioso Islands", 
      "Greece", 
      "Greenland", 
      "Grenada", 
      "Guadeloupe", 
      "Guam", 
      "Guatemala", 
      "Guernsey", 
      "Guinea", 
      "Guinea-Bissau", 
      "Guyana", 
      "Haiti", 
      "Heard Island and McDonald Islands", 
      "Holy See (Vatican City)", 
      "Honduras", 
      "Hong Kong", 
      "Hungary", 
      "Iceland", 
      "India", 
      "Indonesia", 
      "Iran", 
      "Iraq", 
      "Ireland", 
      "Isle of Man", 
      "Israel", 
      "Italy", 
      "Jamaica", 
      "Jan Mayen", 
      "Japan", 
      "Jersey", 
      "Jordan", 
      "Juan de Nova Island", 
      "Kazakhstan", 
      "Kenya", 
      "Kiribati", 
      "Korea, North", 
      "Korea, South", 
      "Kuwait", 
      "Kyrgyzstan", 
      "Laos", 
      "Latvia", 
      "Lebanon", 
      "Lesotho", 
      "Liberia", 
      "Libya", 
      "Liechtenstein", 
      "Lithuania", 
      "Luxembourg", 
      "Macau", 
      "Macedonia", 
      "Madagascar", 
      "Malawi", 
      "Malaysia", 
      "Maldives", 
      "Mali", 
      "Malta", 
      "Marshall Islands", 
      "Martinique", 
      "Mauritania", 
      "Mauritius", 
      "Mayotte", 
      "Mexico", 
      "Micronesia, Federated States of", 
      "Moldova", 
      "Monaco", 
      "Mongolia", 
      "Montserrat", 
      "Morocco", 
      "Mozambique", 
      "Namibia", 
      "Nauru", 
      "Navassa Island", 
      "Nepal", 
      "Netherlands", 
      "Netherlands Antilles", 
      "New Caledonia", 
      "New Zealand", 
      "Nicaragua", 
      "Niger", 
      "Nigeria", 
      "Niue", 
      "Norfolk Island", 
      "Northern Mariana Islands", 
      "Norway", 
      "Oman", 
      "Pakistan", 
      "Palau", 
      "Panama", 
      "Papua New Guinea", 
      "Paracel Islands", 
      "Paraguay", 
      "Peru", 
      "Philippines", 
      "Pitcairn Islands", 
      "Poland", 
      "Portugal", 
      "Puerto Rico", 
      "Qatar", 
      "Reunion", 
      "Romania", 
      "Russia", 
      "Rwanda", 
      "Saint Helena", 
      "Saint Kitts and Nevis", 
      "Saint Lucia", 
      "Saint Pierre and Miquelon", 
      "Saint Vincent and the Grenadines", 
      "Samoa", 
      "San Marino", 
      "Sao Tome and Principe", 
      "Saudi Arabia", 
      "Senegal", 
      "Serbia and Montenegro", 
      "Seychelles", 
      "Sierra Leone", 
      "Singapore", 
      "Slovakia", 
      "Slovenia", 
      "Solomon Islands", 
      "Somalia", 
      "South Africa", 
      "South Georgia and the South Sandwich Islands", 
      "Spain", 
      "Spratly Islands", 
      "Sri Lanka", 
      "Sudan", 
      "Suriname", 
      "Svalbard", 
      "Swaziland", 
      "Sweden", 
      "Switzerland", 
      "Syria", 
      "Taiwan", 
      "Tajikistan", 
      "Tanzania", 
      "Thailand", 
      "Timor-Leste", 
      "Togo", 
      "Tokelau", 
      "Tonga", 
      "Trinidad and Tobago", 
      "Tromelin Island", 
      "Tunisia", 
      "Turkey", 
      "Turkmenistan", 
      "Turks and Caicos Islands", 
      "Tuvalu", 
      "Uganda", 
      "Ukraine", 
      "United Arab Emirates", 
      "United Kingdom", 
      "United States", 
      "Uruguay", 
      "Uzbekistan", 
      "Vanuatu", 
      "Venezuela", 
      "Vietnam", 
      "Virgin Islands", 
      "Wake Island", 
      "Wallis and Futuna", 
      "West Bank", 
      "Western Sahara", 
      "Yemen", 
      "Zambia", 
      "Zimbabwe" ]; 

      $('#country').typeahead({source: location}); 

我曾經有

<input type="text" id="country" data-provide="typeahead" autocomplete="off" class="span3" data-source="location"> 

指我的國家的陣列,但是這是什麼只產生一個單一的一個作爲預輸入的結果。

請幫助...是我的位置jquery/bootstrap源? 我的jquery調用有問題嗎? 我在這裏很困惑。謝謝。

+0

我也知道這裏已經有類似的問題了:http://stackoverflow.com/questions/12187793/bootstrap-typeahead-only-displaying-first-letter,但我沒有做ajax調用,也沒有答案幫助了我。 – angyxpoo

回答

1

貌似有與陣列的一個問題,我做的陣列小,現在的工作,你可以在這裏看到:

UPDATE 你忘了一些逗號數組中從更新的陣列爵士小提琴,在 '孟加拉國' 有它的問題是

http://jsfiddle.net/dT5vJ/2/

請重新檢查你的陣列

var location = ["Afghanistan", "Akrotiri", "Albania", "Algeria", "American Samoa", 
      "Andorra", 
      "Angola", 
      "Anguilla", 
      "Antarctica", 
      "Antigua and Barbuda", 
      "Argentina", 
      "Armenia", 
      "Aruba", 
      "Ashmore and Cartier Islands", 
      "Australia", 
      "Austria", 
      "Azerbaijan", 
      "Bahamas, The" ]; 
+0

謝謝你的幫助。你知道當我修正逗號問題時爲什麼我會得到這個錯誤嗎?HTTP狀態404 - 類型狀態報告 message/PDFAdmin /阿富汗,阿克羅蒂裏,阿爾巴尼亞,阿爾及利亞,美國%20薩摩亞,安道爾,安哥拉,安圭拉,南極洲,安提瓜%20and%20巴布達,阿根廷,亞美尼亞,阿魯巴, %20Islands,澳大利亞,奧地利,阿塞拜疆,巴哈馬,第二十條%,巴林,孟加拉國,巴巴多斯,Bassas%20DA%20India,白俄羅斯,比利時,伯利茲,貝寧,百慕大,不丹,玻利維亞,波斯尼亞%20於是%20Herzegovina .... .. description請求的資源不可用。 – angyxpoo

+0

實際上,我只是從引用中刪除了數組,並將其直接放在兩個單引號內的typeahead調用中。非常感謝。這確實有幫助。 – angyxpoo