2014-10-29 219 views
0

您好我需要得到「源」屬性內的輸入元素:獲取輸入元素從引導預輸入

$('.typeahead').typeahead(null, { 
    source: function (query, process) { 
     var element = $(this); 

我期待一個「輸入」的元素,但我得到:

[Dataset, jquery: "2.1.1", constructor: function, selector: "", toArray: function, get: function…] 

回答

2

在事先鍵入的內容Twitter的引導3.0改變了 「這個」 對象設置的方式。

我可以訪問輸入元素以這樣的方式

var element = $(this.$el[0].parentElement.parentElement).children("input").first(); 

醜......

0

不是很確定如果我完全理解你的問題:/

而不是var element = $(this);使用:

var element = $(this)[0]; 

或者更好的是:

var element = this; 

UPDATE

- 對建議的後臺數據源。預期是具有簽名(query,cb)的 函數。預計 函數將計算用於查詢的建議集合(即,對象的JavaScript數組),然後用所述集合調用cb。 cb可以同步或異步調用 。 Bloodhound建議引擎可以使用 來學習如何使用,參見Bloodhound Integration。 需要

參考

https://github.com/twitter/typeahead.js/blob/master/doc/jquery_typeahead.md 
https://github.com/twitter/typeahead.js/blob/master/doc/jquery_typeahead.md#bloodhound-integration 
+0

我得到了相同的結果。 – Beetlejuice 2014-10-29 19:19:10

+0

我已經挖掘到這些網站,但沒有運氣。也許我忘記了一些東西,因爲在另一個使用bootstrap 2.0的項目中工作。 – Beetlejuice 2014-10-29 19:37:45