2016-09-07 31 views
0

我想使用Typeahead和bloodhound框架從遠程API調用中搜索api路徑的響應。Typeahead遠程無查詢

通過示例url api.example.com/getEndpoints我會收到一個包含所有端點的對象。 我想讓打字過濾這些端點。據我所知你想在使用遠程時指定一個查詢,這顯然不能,因爲我只是在一個請求中收到所有的端點。

有什麼方法或建議來解決這個問題嗎?

我的代碼看起來像

// Instantiate the Bloodhound suggestion engine 
var endpoints = new Bloodhound({ 
    datumTokenizer: function (datum) { 
     console.log('datumTokenizer, datum: ', datum, ', datum.value: ', datum.value); 
     return Bloodhound.tokenizers.whitespace(datum.value); 
    }, 
    queryTokenizer: Bloodhound.tokenizers.whitespace, 
    remote: { 
     url: 'https://api.example.com/getEndpoints', 
     filter: function (endpoints) { 
      console.log(endpoints); 
      // Map the remote source JSON array to a JavaScript object array 
      return Object.keys(endpoints).map(function (endpointPath) { 
       console.log(endpointPath); 
       return { 
        value: endpointPath 
       }; 
      }); 
     } 
    }, 
    limit: 10 
}); 

// Initialize the Bloodhound suggestion engine 
endpoints.initialize(); 

// Instantiate the Typeahead UI 
$('#inputPath').typeahead(
    { 
     hint: true, 
     highlight: true, 
     minLength: 1 
    }, { 
     displayKey: 'value', 
     source: endpoints.ttAdapter() 
    } 
); 
+0

任何解決方案,我也需要? – Hashaam

+0

不 - 我相信我從來沒有找到解決方案,並決定使用另一個框架來解決我的問題。我很抱歉 – Daniel

回答