我试图整合引导3插件事先键入的内容(主要是从旧的引导预输入功能的端口它在引导3移除之前,如果我理解正确的话)与引导-Tagsinput插件。
我没有问题让它们单独工作,包括JSON预取预输入功能。我不明白如何将两者融合在一起。我认为应该不会太难,但是我显然缺乏对Javascript的了解。
这是我的输入字段:
<input type="text" id="tagFilter" data-provide="typeahead" data-role="tagsinput">
这是在Javascript中调用typeahead插件的方式:
//The typeahead
$.get('tags.php', function(data){
$("#tagFilter").typeahead({ source:data });
},'json');
如果有帮助,Tagsinput在其文档中有一个示例,说明如何实现twitter typeahead.js:
$('input').tagsinput();
// Adding custom typeahead support using http://twitter.github.io/typeahead.js
$('input').tagsinput('input').typeahead({
prefetch: 'citynames.json'
}).bind('typeahead:selected', $.proxy(function (obj, datum) {
this.tagsinput('add', datum.value);
this.tagsinput('input').typeahead('setQuery', '');
}, $('input')));
但我使用的是其他插件。我发现一个人在我头上。
再次感谢。
好的...所以我实际上已经决定使用Twitter typeahead.js,因为我设法使其正常运行。我使用了以下代码,如果不是最佳方法,请指出。
<input type="text" id="tagFilter" data-provide="typeahead" value="test,arlington">
$('#tagFilter').tagsinput({
typeahead: {
source: $.get('tags.php')
}
});
我的tags.php文件只是一个列表,我认为要使其与JSON文件中带有键的关联数组一起使用,还需要做很多工作。我决定对我的情况没有任何好处,因为我只关心用于查询目的的标签名称。
所以我的tags.php只是回显以下结果:
//the mySQLi query is above...
while ($row = mysqli_fetch_assoc($result)) {
$tags[] = $row['tag_name'];
}
echo json_encode($tags);
希望有人能受益。
本文收集自互联网,转载请注明来源。
如有侵权,请联系[email protected] 删除。
我来说两句