我使用羊駝毛窗體來生成一個窗體,一個字段將有一個自動完成。我正在測試http://www.alpacajs.org/docs/fields/text.html中的示例7,以瞭解它是如何工作的。但是,在我的表單中,自動填充顯示爲在Alpaca網站上與Cloud CMS的{「value」:「Cloud CMS」}。我也嘗試直接指定自動完成值作爲數組。以下是我的代碼,noteahead.js是本地安裝的。自動完成顯示使用羊駝形式的鍵和值
<html>
<head>
<title>Alpaca-Autocomplete Form</title>
<script type="text/javascript" src="http://code.jquery.com/jquery-1.11.1.min.js"></script>
<link type="text/css" rel="stylesheet" href="http://maxcdn.bootstrapcdn.com/bootstrap/3.3.2/css/bootstrap.min.css" />
<script type="text/javascript" src="http://maxcdn.bootstrapcdn.com/bootstrap/3.3.2/js/bootstrap.min.js"></script>
<link type="text/css" href="http://code.cloudcms.com/alpaca/1.5.14/bootstrap/alpaca.min.css" rel="stylesheet" />
<script type="text/javascript" src="http://cdnjs.cloudflare.com/ajax/libs/handlebars.js/3.0.3/handlebars.js"></script>
<script type="text/javascript" src="http://code.cloudcms.com/alpaca/1.5.14/bootstrap/alpaca.min.js"></script>
<!-- typeahead.js https://github.com/twitter/typeahead.js -->
<script src="bower_components/typeahead.js/dist/bloodhound.min.js" type="text/javascript"></script>
<script src="bower_components/typeahead.js/dist/typeahead.bundle.min.js" type="text/javascript"></script>
</head>
<body>
<div id="field7"> </div>
<script>
var companies = ["Cloud CMS", "Amazon", "HubSpot"];
$("#field7").alpaca({
"schema": {
"type": "string"
},
"options": {
"type": "text",
"label": "Company Name",
"helper": "Select the name of a cloud computing company",
"typeahead": {
"config": {
"autoselect": true,
"highlight": true,
"hint": true,
"minLength": 1
},
"datasets": {
"type": "local",
"source": companies
// "source": function(query) {
// var companies = ["Cloud CMS", "Amazon", "HubSpot"];
// var results = [];
// for (var i = 0; i < companies.length; i++) {
// var add = true;
// if (query) {
// add = (companies[i].indexOf(query) === 0);
// }
// if (add) {
// results.push({
// "value": companies[i]
// });
// }
// }
// return results;
// }
}
}
}
});
</script>
</body>
</html>
是的,那解決了它 - 謝謝!我使用了bower install typeahead.js來安裝,有什麼線索讓你嘗試不同的版本? – tw1742
這很簡單,我只是試圖看看他們在圖書館的官方網站使用什麼版本。順便說一下,我現在在工作中使用羊駝近一年,我發現它非常有用和簡單易用,但有時涉及到定製......我討厭這麼多,因爲我無法找到我的問題的答案,加上其github社區並不是非常活躍。無論如何,我不是要求你嘗試其他替代方案或本地代碼來生成你的表單,堅持它,它非常有用,並提供很多東西,你可以從中學到太多:) – vert3x
任何想法爲這一個http ://stackoverflow.com/questions/34127172/using-remote-data-for-autocomplete-with-alpaca-forms – tw1742