簡體   English   中英

jquery autocomplete使用多個源(本地json api和jsonp)

[英]jquery autocomplete use multiple sources (local json api and jsonp)

基本上我有一個酒店搜索引擎,在網站頂部有一個搜索字段,必須顯示自動完成結果。 結果可以是酒店或地點(城市)。 可與Facebook自動填充相比(搜索可以是人,頁面......)

我從基本的geonames jsuery例子開始: http//jqueryui.com/autocomplete/#remote-jsonp

但我無法弄清楚如何使用我自己的JSON api酒店。 我知道我應該將我的JSON酒店與地理名稱合並嗎? 有誰能告訴我這是怎么回事?

最簡單的高級代碼應該如下所示,其中requestFromSource1是您請求地理名稱的地方,requestFromSource2是您查詢自己的自動完成引擎的地方。

  $( "#city" ).autocomplete({
        source: function( request, response ) {
    var resultFromSource1 = null;
    var resultFromSource2 = null;
    var agregateResults = function(){
        if( resultFromSource1 && resultFromSource2){
            var result = resultFromSource1.concat(resultFromSource2);
            response(result);
        }
    }
    requestFromSource1(function( result ){
        resultFromSource1 = result;
        agregateResults();
    });
    requestFromSource2(function( result ){
        resultFromSource2 = result;
        agregateResults();
    });
        }
    });
});

更復雜的情況是通過相關性得分合並。 在你的情況下,我擔心這個說明是可能的。

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM