2013-07-08 33 views
1

我試圖把我自己的exampleahead.js(http://twitter.github.io/typeahead.js/examples/)的例子放在一起,由於某種原因,我無法讓它工作。我的typeahead,js例子有什麼問題?

小提琴:http://jsfiddle.net/A8P3C/

我已經包括了我的JSON,它應該從源代碼中的「本地」調用加載。

<div class="example example-degrees"> 
<h2 class="example-name">Degrees</h2> 

    <div class="demo"> 
     <input class="typeahead" type="text" placeholder="degrees"> 
    </div> 

$(document).ready(function() { 
$('.countries .typeahead').typeahead({ 
name: 'degrees', 
local: ["Bachelor of Science","Bachelor of Science in Accounting","Bachelor of Science in Business","Bachelor of Science in Business\/Accounting","Bachelor of Science in Business\/Administration","Bachelor of Science in Business\/Communications","Bachelor of Science in Business\/e-Business","Bachelor of Science in Business\/Finance","Bachelor of Science in Business\/Global Business Management","Bachelor of Science in Business\/Green and Sustainable","Bachelor of Science in Business\/Green and Sustainable Enterprise Management","Bachelor of Science in Business\/Hospitality Management","Bachelor of Science in Business\/Human Resource Management"] 
}); 

我想我可能只是設置一個簡單的例子,但我不能讓它工作

TIA

回答

3

你已經錯過了封閉的括號內爲.ready及其回調函數。

$(document).ready(function() { 
    $('.example-countries .typeahead').typeahead({ 
    name: 'countries', 
    local: ["Bachelor of Science", 
      "Bachelor of Science in Accounting", 
      "Bachelor of Science in Business", 
      "Bachelor of Science in Business\/Accounting", 
      "Bachelor of Science in Business\/Administration", 
      "Bachelor of Science in Business\/Communications", 
      "Bachelor of Science in Business\/e-Business", 
      "Bachelor of Science in Business\/Finance", 
      "Bachelor of Science in Business\/Global Business Management", 
      "Bachelor of Science in Business\/Green and Sustainable", 
      "Bachelor of Science in Business\/Green and Sustainable Enterprise Management", 
      "Bachelor of Science in Business\/Hospitality Management", 
      "Bachelor of Science in Business\/Human Resource Management"] 
    }); // <-- add missing closing bracket for ready(). 

而且typeahead.js文件,您包含不正確,因爲它是純文本。您需要鏈接到this file

Here is the your updated jsFiddle demo

+0

Thanks!我知道這是簡單的 – weggie

+3

似乎jsFiddle不再起作用? :( – hlyates