gpt4 book ai didi

javascript - 自动完成使用羊驼形式显示键和值

转载 作者:行者123 更新时间:2023-11-29 15:31:49 25 4
gpt4 key购买 nike

我正在使用 Alpaca 表单生成一个表单,其中一个字段将具有自动完成功能。我正在测试 http://www.alpacajs.org/docs/fields/text.html 中的示例 7看看这是如何工作的。但是,在我的表单中,自动完成显示为 {"value":"Cloud CMS"} 与 Alpaca 网站上的 Cloud CMS。我还尝试直接将自动完成值指定为数组。下面是我的代码,注意 typeahead.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>

最佳答案

我试过你的代码,问题是你使用的 typeahead 版本。我将版本更改为版本 0.10.5它有效,请尝试使用此版本并告诉我它是否有效。

祝你有美好的一天。

关于javascript - 自动完成使用羊驼形式显示键和值,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/34101466/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com