是否可以将一些HTML附加到typeahead的末尾?我尝试过很多不同的东西,但都没有。
我要做的是将typeahead的最后结果设为Search for "< what the user typed into the input >"
。
以下是我在JSFiddle上尝试的内容:http://jsfiddle.net/MgcDU/8621/
我期望它做的是在创建后的下拉列表末尾添加<li>
,但事实并非如此。为什么呢?
HTML:
<input type="text" data-source="["Alabama","Alaska","Arizona","Arkansas","California","Colorado","Connecticut","Delaware","Florida","Georgia","Hawaii","Idaho","Illinois","Indiana","Iowa","Kansas","Kentucky","Louisiana","Maine","Maryland","Massachusetts","Michigan","Minnesota","Mississippi","Missouri","Montana","Nebraska","Nevada","New Hampshire","New Jersey","New Mexico","New York","North Dakota","North Carolina","Ohio","Oklahoma","Oregon","Pennsylvania","Rhode Island","South Carolina","South Dakota","Tennessee","Texas","Utah","Vermont","Virginia","Washington","West Virginia","Wisconsin","Wyoming"]" data-items="10" data-provide="typeahead" style="margin: 0 auto;" class="span3">
jQuery的:
$(".typeahead.dropdown-menu").append('<li data-value="Custom" class=""><a href="#">CUSTOM TEXT</a></li>');
答案 0 :(得分:0)
下拉菜单是在先行过滤过程中构建的。如果你“加载”检查它,你会发现它是空的。
根据您尝试解决的具体问题,我可以考虑两种可能的解决方案。
一种解决方案是扩展typeahead插件并提供自定义“渲染”功能。这将允许您修改列表呈现过程并附加其他<li>
以及您喜欢的任何其他内容。这可能被视为“最佳方式”。
另一个更糟糕的解决方案是将自定义值放在数据源中,然后提供自定义“匹配器”功能,该功能运行原始匹配器以及自定义值的附加子句。
当然,解决方案与问题有关,并且在不知道您想要做什么的具体细节的情况下,我不能推荐使用哪一个。但就我所能想的那些,这是你的两个选择。