如何将数组值传递给Jquery数据表的columns属性

时间:2015-02-25 14:40:53

标签: jquery jquery-ui datatables jquery-datatables

我想将变量传递给mColumns属性而不是[0,1,2,3,4,5,6,7,8,9],这是我的代码:

$(function() {
 var table=$('#MSRRes').dataTable
( {

 "oTableTools": 
 {
    "sSwfPath": "swf/copy_csv_xls_pdf.swf",
    "aButtons": [
               {
                   "sExtends": "csv",
                   "mColumns": [0, 1, 2, 3,4,5,6,7,8,9],
                   "sAction":     "flash_save"

             }
    ]
  }
});
});

1 个答案:

答案 0 :(得分:1)

你的意思是这样吗?

var someArray=[0, 1, 2, 3,4,5,6,7,8,9];

(function() {

var table=$('#MSRRes').dataTable ( {

 "oTableTools": 
 {
    "sSwfPath": "swf/copy_csv_xls_pdf.swf",
    "aButtons": [
               {
                   "sExtends": "csv",
                   "mColumns": someArray,
                   "sAction":     "flash_save"

             }
    ]
  }
});
});