0

オートコンプリート jquery ツールの使用に問題があります

クライアント側 :

JQElement.autocomplete({
   source:  function (request, response) {
        $.ajax({
            url: jsonAction,
            dataType: "json",
            data: {
                maxRows: 10,
                startsWith: request.term
            },
            success: function( data ) {
                response( $.map( data , function( item ) {
                        return {
                                label: item.label,
                                value: item.value
                        }
                }));
                //response(data);
            },
            error: function(message, status, errorThrown) {
                alert("une erreur s'est produit lors de la recherche des éléments correspondant à la saisie. Contacter les créateurs du programme");
            }
        });
    },
    minLength: 1
 });

アクションは次のように呼び出されます。

public String getInsuredNumbers() {
    try {
        String maxRows = request.getParameter("maxRows");
        String startsWith = request.getParameter("startsWith");

        if(maxRows.equals("")) maxRows = "10";
        if(startsWith.equals("")) startsWith = "17";

        String sql = "select assure.ASS_nni, assure.ASS_nom, assure.ASS_prenom from assure where "
                + "assure.ASS_nni like '" + startsWith + "%' limit " + maxRows;
        ResultSet rs = this.getResponse(sql);

        while(rs.next()) {
            Param p = new Param(rs.getString(1), rs.getString(1) + " " + rs.getString(2) + " " + rs.getString(3));
            data.add(p);
        }


    } catch (SQLException ex) {
        Logger.getLogger(AutocompleteAction.class.getName()).log(Level.SEVERE, null, ex);
    } finally {
        return SUCCESS;
    }
}

public List<Param> getData() {
    return data;
}

data は Param の ArrayList です

public class Param {
  private String value;
  private String label;

  public Param(String value, String label) {
    this.value = value;
    this.label = label;
  }

  public String getLabel() {
    return label;
  }

  public String getValue() {
    return value;
  }

}

Firebug のバグは、json の回答が適切であり、クライアント側で成功の回答がトリガーされることを示しています

ただし、入力の下のリストは空のようです

それを手伝ってもらえますか?

ありがとうございました

4

1 に答える 1

0

解決

クライアント側:

JQElement.autocomplete({
   source:  function (request, response) {
        $.ajax({
            url: jsonAction,
            dataType: "json",
            data: {
                maxRows: 10,
                startsWith: request.term
            },
            success: function( data ) {
                var mydata;

                $.map(data, function(item, i) {
                    if(i == "data") {
                        mydata = item;
                    }
                });

                response( $.map( mydata , function( item) {
                        return {
                            label: item.label,
                            value: item.value
                        }
                }));
            },
            error: function(message, status, errorThrown) {
                alert("une erreur s'est produit lors de la recherche des éléments correspondant à la saisie. Contacter les créateurs du programme");
            }
        });
    },
    minLength: 1,
于 2012-05-30T11:21:36.467 に答える