我创建了一个表格来绑定到数据表请求:

val datatableForm = Form(
  tuple(
    "draw" -> number,
    "start" -> number,
    "length" -> number,
    "search" -> tuple(
        "value" -> text,
        "regex" -> boolean
    ),
    "columns" -> seq(tuple(
        "data" -> number,
        "name" -> text,
        "orderable" -> boolean,
        "search" -> tuple(
            "value" -> text,
            "regex" -> boolean
        )
      )
    ),
    "order" -> seq(tuple(
        "column" -> number,
        "dir" -> text
      )
    )
  )
)


在我的请求中,我致电val form = datatableForm.bindFromRequest。这对于drawstartlength变量非常有效,但对于searchcolumnsorder变量却无效。例如,当我不使用嵌套元组时,可以调用datatableForm.bindFromRequest.get,它将返回Some对象,但是当我添加嵌套元组并调用get时,它将返回None对象。

从datatables javascript对象发送的数据是:

{
  "draw": 1,
  "columns": [
    {
      "data": 0,
      "name": "",
      "searchable": true,
      "orderable": true,
      "search": {
        "value": "",
        "regex": false
      }
    },
    {
      "data": 1,
      "name": "",
      "searchable": true,
      "orderable": true,
      "search": {
        "value": "",
        "regex": false
      }
    }
  ],
  "order": [
    {
      "column": 0,
      "dir": "asc"
    }
  ],
  "start": 0,
  "length": 10,
  "search": {
    "value": "",
    "regex": false
  }
}


这是请求正文中的数据:

Map(draw -> ArrayBuffer(1), columns[0][data] -> ArrayBuffer(0), columns[0][name] -> ArrayBuffer(), columns[0][searchable] -> ArrayBuffer(true), columns[0][orderable] -> ArrayBuffer(true), columns[0][search][value] -> ArrayBuffer(), columns[0][search][regex] -> ArrayBuffer(false), columns[1][data] -> ArrayBuffer(1), columns[1][name] -> ArrayBuffer(), columns[1][searchable] -> ArrayBuffer(true), columns[1][orderable] -> ArrayBuffer(true), columns[1][search][value] -> ArrayBuffer(), columns[1][search][regex] -> ArrayBuffer(false), order[0][column] -> ArrayBuffer(0), order[0][dir] -> ArrayBuffer(asc), start -> ArrayBuffer(0), length -> ArrayBuffer(10), search[value] -> ArrayBuffer(), search[regex] -> ArrayBuffer(false))


如何获取表格绑定到嵌套元组?

最佳答案

我看到了同样的错误。问题是请求没有作为json发送。确保将contentType设置为json

如果您使用的是jQuery,则文档位于here中,以了解有关操作方法。

本质上是这样的:

$.ajax({
  type: "POST",
  url: youUrl,
  data : data,
  contentType: "application/json"
});

08-18 21:18