2013-10-28 69 views
1

我可以看到一個很好的控制引導-tagsinput不工作

http://timschlechter.github.io/bootstrap-tagsinput/examples/

但基於它我想它下面的代碼沒有工作, 任何一個可以幫助我

<script type="text/javascript" src="jquery-1.10.2.min.js" ></script> 

<script src="http://timschlechter.github.io/bootstrap-tagsinput/examples/bower_components/angular/angular.min.js"></script> 
<script src="http://timschlechter.github.io/bootstrap-tagsinput/examples/bower_components/google-code-prettify-lite/prettify.js"></script> 
<script src="http://timschlechter.github.io/bootstrap-tagsinput/examples/bootstrap-2.3.2/js/bootstrap.min.js"></script> 
<script src="http://timschlechter.github.io/bootstrap-tagsinput/dist/bootstrap-tagsinput.js"></script> 
<script src="http://timschlechter.github.io/bootstrap-tagsinput/dist/bootstrap-tagsinput-angular.js"></script> 

<body> 
<br /> 
<input type="text" value="" data-role="tagsinput" /> 
<br /> 
</body> 
<script> 
$('input').tagsinput({ 
    typeahead: { 
    source: [{"value":1,"text":"Amsterdam"}, 
{"value":4,"text":"Washington"}, 
{"value":7,"text":"Sydney"}, 
{"value":10,"text":"Beijing"}, 
{"value":13,"text":"Cairo"}] 
    } 
}); 
</script> 
+0

修復路徑bootstrap.min.js – SaudiD3mon

+0

這不是問題 –

+0

我得到類型錯誤:tagsinput [ARG1]是不是一個功能 –

回答

0

我在項目中使用相同的插件 typeahead源的問題它需要是簡單元素的json沒有對象

看看這個小提琴,我敢肯定,它會幫助你

Fiddle

$('input').tagsinput({ 
    typeahead: { 
     source: function (query, process) { 
      cities = []; 
      map = {}; 

      var data = [{ 
       "value": 1, 
        "text": "Amsterdam" 
      }, { 
       "value": 4, 
        "text": "Washington" 
      }, { 
       "value": 7, 
        "text": "Sydney" 
      }, { 
       "value": 10, 
        "text": "Beijing" 
      }, { 
       "value": 13, 
        "text": "Cairo" 
      }]; 

      $.each(data, function (i, city) { 
       map[city.text] = city; 
       cities.push(city.text); 
      }); 

      return (cities); 
     } 
    } 
}); 

預取的Json

cities = []; 
map = {}; 

var preFetchResult = function (query, callback) { 
    $.get("/cities", { 
     "data": query 
    }, function (data) { 
     $.each(data, function (i, city) { 
      map[city.text] = city; 
      cities.push(city.text); 
     }); 
    }); 
}; 

preFetchResult.done(function (response) { 
    $('input').tagsinput({ 
     typeahead: { 
      source: function (query, process) { 
       return (cities); 
      } 
     } 
    }); 
}); 
+0

如何在您的示例中使用預取JSON數據? – dcclassics

+0

檢查更新的答案,使用get作爲承諾,讓我知道它是否適合你=) – ppollono