我正在使用coffe脚本生成数据表的javascript代码,如下所示:
class App.Empresas extends App.Base
inventarios: ->
$ ->
$('#tabla_inventarios').dataTable
ajax: $('#tabla_inventarios').data('source')
columns: [
data: "id_producto",
data: "nombre",
data: "categoria"
]
但是使用rails log的请求显示了这个json:
Parameters: {"draw"=>"1", "columns"=>{"0"=>{"data"=>"categoria", "name"=>"", "searchable"=>"true", "orderable"=>"false", "search"=>{"value"=>"", "regex"=>"false"}}}, "start"=>"0", "length"=>"10", "search"=>{"value"=>"", "regex"=>"false"}, "_"=>"1495682354559", "id"=>"85858-5"}
如您所见,它只发送1列(“categoria”),它应该发送3 ..
答案 0 :(得分:0)
您正在更换相同的密钥'数据'有不同的价值观。要获得3个键值对对象,请按如下所示更改代码:
class App.Empresas extends App.Base
inventarios: ->
$ ->
$('#tabla_inventarios').dataTable
ajax: $('#tabla_inventarios').data('source')
columns: [
{data: "id_producto"},
{data: "nombre"},
{data: "categoria"}
]
或者如果你想要字符串数组,请执行
class App.Empresas extends App.Base
inventarios: ->
$ ->
$('#tabla_inventarios').dataTable
ajax: $('#tabla_inventarios').data('source')
columns: [
"id_producto",
"nombre",
"categoria"
]