2015-05-14 117 views
0

我正在使用建議框來實現GWT中的自動完成。 爲了從實體中檢索數據,我使用了對象化和映射數據來建議框我已經使用MultiWordSuggestOracle。GWT自動完成或建議框

在表單加載我觸發查詢檢索數據並將其傳遞給MultiWordSuggestOracle。它工作正常。

對於例如,如果我加載客戶數據的建議,它正在

但對於例如,如果我有5000 - 我的實體50000客戶記錄,所以檢索所有數據,並顯示在建議可能不會成功。

那麼是否有任何其他技術在gwt中使用自動完成? 在此先感謝

回答

0

而不是加載所有客戶記錄在表格加載,動態篩選後端數據基於用戶輸入到SuggestBox。您可以通過實施自定義SuggestOracle(可能擴展MultiWordSuggestOracle)來完成此操作。

public class ServerSuggestOracle extends SuggestOracle{ 

    protected DataSource datasource; 
    protected int startQueryLength; 
    protected ArrayList<T> suggestions = new ArrayList<T>(); 
    protected boolean isMoreSuggestions = false; 
    protected int previousQueryLength = 0; 

    public ServerSuggestOracle(DataSource datasource,int startQueryLength) 
    { 
     super(); 
     this.datasource = datasource; 
     this.startQueryLength = startQueryLength; 

    } 

    @Override 
    public void requestSuggestions(final Request request, final Callback callback) { 
     // start the backend call only if the user types in more than startQueryLength characters. 
     if (request.getQuery().length() < startQueryLength) 
      return; 
     // if the user expands the search or a serach hasn't been carried out, call the backend. Otherwise filte the existing list 
     if (isMoreSuggestions || previousQueryLength > request.getQuery().length() || suggestions.size() == 0) 
     { 
      datasource.fetchDataFromBackend(request.getQuery(), new FetchDataFromBackendCallback() { 

       @Override 
       public void onFetchData(ArrayList<T> genes,Integer count,boolean isMore) { 

        suggestions.clear(); 
        for (int i = 0;i<genes.size();i++) { 
         Suggestion suggestion = new Suggestion(); 
         suggestions.add(suggestion); 
        } 
        SuggestOracle.Response response = new SuggestOracle.Response(suggestions); 
        isMoreSuggestions = isMore; 
        if (count != null) 
         response.setMoreSuggestionsCount(count); 
        else 
         response.setMoreSuggestions(isMore); 
        previousQueryLength = request.getQuery().length(); 
        callback.onSuggestionsReady(request,response); 
       } 
      }); 
     } 
     else 
     { 
      super.requestSuggestions(request,cabllack); 
     } 
    } 

} 
+0

感謝您的回覆。 – user3469842