普通网友 2017-05-25 03:42
浏览 31

参数仅显示最后一列

I'm using coffe script to generate the javascript code for the datatables, like this:

class App.Empresas extends App.Base
inventarios: ->
$ ->
  $('#tabla_inventarios').dataTable
    ajax: $('#tabla_inventarios').data('source')
    columns: [
        data: "id_producto", 
    data: "nombre", 
    data: "categoria"
]

but the request using rails log shows this 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"}

As you can see it only sends 1 column ("categoria") and it should send 3..

  • 写回答

1条回答 默认 最新

  • weixin_33713707 2017-05-25 04:13
    关注

    You are replacing the same key 'data' with different values. To get 3 key-value pair objects, change your code as follows:

    class App.Empresas extends App.Base
    inventarios: ->
    $ ->
      $('#tabla_inventarios').dataTable
        ajax: $('#tabla_inventarios').data('source')
        columns: [
            {data: "id_producto"}, 
            {data: "nombre"}, 
            {data: "categoria"}
    ]
    

    or if you want array of strings, do

    class App.Empresas extends App.Base
    inventarios: ->
    $ ->
      $('#tabla_inventarios').dataTable
        ajax: $('#tabla_inventarios').data('source')
        columns: [
            "id_producto", 
            "nombre", 
            "categoria"
    ]
    
    评论

报告相同问题?