2015-05-14 80 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