2013-07-31 1 views
0

그래서 부트 스트랩 타입 어 헤드를 사용하여 국가 목록을 채우려고합니다. 그 사람이 살고있는 나라의 텍스트 필드에 타이핑을 시작한 다음, 선택할 수있는 옵션을 보여줄 것입니다.트위터 부트 스트랩 Typeahead는 "a"라는 문자를 채우는 것입니다.

처음에는 데이터 소스가 문자열로 설정된 거대한 배열의 변수 인 변수로 설정되었습니다. "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,하지만 나는 아약스 전화를하지 않고 대답도하지 않는다. 도와 줬어. – angyxpoo

답변

1

가 보이는, 내가 배열 작게 그리고 당신은 여기에서 볼 수 있습니다, 지금 작동합니다

당신은에서 배열의 업데이트 된 배열을 일부 쉼표를 잊어 UPDATE '방글라데시'에서 JS 바이올린이이 문제를입니다

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 - 유형 상태 보고서 메시지/PDFAdmin/아프가니스탄, 알타니아, 알제리, 알제리, 미국 20 % 사우디 아라비아, 안도라, 앙골라, 앤 구라, 남극 Antigua % 20and % 20Barbuda, 아르헨티나, 아르메니아, 아루바, Ashmore % 20and % 20Cartier 벨리즈, 벨기에, 벨리즈, 베냉, 버뮤다, 부탄, 볼리비아, 보스니아 % 20and % 20Herzegovina, % 20Islands, 호주, 오스트리아, 아제르바이잔, 바하마, % 20The, 바레인, 방글라데시, 바베이도스, Bassas % 20da % 20India .. 설명 요청한 리소스를 사용할 수 없습니다. – angyxpoo

+0

사실, 방금 참조 된 배열을 제거하고 두 개의 작은 따옴표 ''내에서 타입 어 헤드 호출에 직접 배치했습니다. 정말 고맙습니다. 이것은 도움이되었습니다. – angyxpoo