0

我有一个包含多行条目的数据表,并希望将其设置为服务器端。问题是我无法得到sEcho对我request()来说总是如此null的东西。我的代码如下:

    $.fn.loadTable = function (url,options) {

    // check if the options exists or not, defaults to false
    var activity = ((typeof options === "undefined") || (typeof options.activity === "undefined")) ? false : options.activity;
    var document = ((typeof options === "undefined") || (typeof options.document === "undefined")) ? false : options.document;
    var idable   = ((typeof options === "undefined") || (typeof options.idable === "undefined")) ? false : options.idable;

    var element = this;

    var table = element.find("table").dataTable({
            "bProcessing": true,
            "bServerSide": true,
            "bPaginate": false,
        "bLengthChange": false,
        "bFilter": true,
        "bSort": true,
        "bInfo": false,
        "bAutoWidth": false,
        "oLanguage": {
            "sZeroRecords": "No data available"
        }
    });     

    $.ajax({
        'url':url,
        dataType:"json",
        type:'GET',
        success: function(data) {                       
            $.each(data,function(index,item) {....

我的控制器看起来像这样:

    public static Result getActivitiesByParticipant() throws UnsupportedEncodingException {
    List<Container> activities = CMISConnection.listActivitiesByParticipant(session("user"));   
            // TODO: change to server side
            // manipulate jsonresult
            ObjectNode result = Json.newObject();
            Map<String, String[]> params = request().queryString();
            result.put("sEcho", Integer.valueOf(params.get("sEcho")[0]));
            result.put("iTotalRecords", activities.size());
            result.put("iTotalDisplayRecords", activities.size());

            ArrayNode an = result.putArray("aaData");

            for(Container c : activities) {
              ObjectNode row = Json.newObject();
              row.put("0", c.getName());
              row.put("1", c.getCreator());
              row.put("2", dateFormat.format(c.getCreationDate()));
              row.put("3", c.getOptischerBetreff());
              an.add(row);
            }
    return ok(result);
}

paramsnull对我来说总是如此。我配置了路线

GET     /activity/participant                           controllers.Content.getActivitiesByParticipant()
4

1 回答 1

0

Params 可能为 null,因为您的 url 不包含查询字符串。网址是什么样的?

下面是一个综合打法 2.0 + 数据表的例子,以防万一,你以前没有遇到过。

于 2013-10-26T15:56:01.333 回答