试图获得TypeAhead& Twitter引导程序可以使用AJAX / Json调用...它可以在没有Ajax的情况下运行。
获取错误说:无法获取未定义或空引用的属性长度
<var id="result-container" class="result-container"></var>
<div class="container">
<div class="row">
<input id="field" placeholder="Start typing.." class="typeahead" data-items="3" type="text">
</div>
<div class="row" id="addRow">
<button id="btnAddRow" class="btn">Add Row</button>
</div>
</div>
<script type="text/javascript">
var typeaheadSettings = {
source: function (typeahead, query) {
return $.get('search.json', { query: query }, function (data) {
return typeahead.process(data);
});
// return ['dingbat','alpha','asphalt','beta','bravo','delta','epsilon','gamma','zulu'];
}
};
$('.typeahead').typeahead(typeaheadSettings); /* init first input */
$('#btnAddRow').click(function(){
var newRow = $('<div class="row"><input type="text" placeholder="Start typing.." class="typeahead" data-items="3"></div>');
newRow.insertBefore('#addRow');
$('.typeahead').trigger('added');
});
$('.typeahead').on('added',function(){
$('.typeahead').typeahead(typeaheadSettings);
});
</script>