在Twiiter Bootstrap v2中整合Typeahead / JSON数据源?

时间:2012-02-20 22:27:37

标签: php javascript html json twitter-bootstrap

我有多个字段需要BS2的新Typeahead功能。我不想重复表单上每个字段的数据,而是将其整合到一个地方,可能是JS文件。我只是不确定语法。

以下是我对其中一个领域的看法:

<input data-provide="typeahead" data-items="6" data-source='["4","4.5","5","5.5","6","6.5","7","7.5","8","8.5","9","9.5","10","10.5","11","11.5","12","12.5","13","13.5","14","14.5","15","15.5","16","16.5","17","17.5","18","18.5","19","19.5","W5","W5.5","W6","W6.5","W7","W7.5","W8","W8.5","W9","W9.5","W10","W10.5","W11","W11.5","W12","W12.5","W13","W13.5","W14","1Y","1.5Y","2Y","2.5Y","3Y","3.5Y","4Y","4.5Y","5Y","5.5Y","6Y","6.5Y","7Y","1C","1.5C","2C","2.5C","3C","3.5C","4C","4.5C","5C","5.5C","6C","6.5C","7C","7.5C","8C","8.5C","9C","9.5C","10C","10.5C","11C","11.5C","12C","12.5C","13C","13.5C","OS","N/A"]' name="size1" type="text" class="span1" autocomplete="off">

1 个答案:

答案 0 :(得分:3)

Bootstrap中的typeahead功能实际上只是jQuery UI的autocomplete功能

跳过data-provide属性,并自行初始化字段。你应该可以说

$('.typeahead').typeahead({
  source: [ ... your array ... ]
});

这就是Bootstrap's own docs所说的,它匹配jQuery UI's docs for Autocomplete