1

当我像这样手动推送参数时: aoData.push( { "name": "process", "value": "fetch" } ); 它运行良好,没有任何错误消息。

但是,现在我想在脚本顶部声明数组 tableXtraPostParams 并将这个数组的参数一一推送到 aoData

这是一段代码工作正常

var tableXtraPostParams = {
    "process":"fetch",
    "which":"mine"
};
$.each(tableXtraPostParams, function(n, v){
    aoData.push( {
       "name": n, 
       "value": v
    } );
});

但是我在 JS 日志中收到错误消息

语法错误,无法识别的表达式:[object Object]

在此处输入图像描述

我在这里想念什么?

任何建议将不胜感激!

更新

我知道这个错误与我的修改有关。(因为当我删除时$.each,我没有收到任何这样的错误)

这是Aodata在推送之前的样子

[Object { name="sEcho", value=1}, Object { name="iColumns", value=8}, Object { name="sColumns", value=""}, Object { name="iDisplayStart", value=0}, Object { name="iDisplayLength", value=25}, Object { name="mDataProp_0", value=0}, Object { name="mDataProp_1", value=1}, Object { name="mDataProp_2", value=2}, Object { name="mDataProp_3", value=3}, Object { name="mDataProp_4", value=4}, Object { name="mDataProp_5", value=5}, Object { name="mDataProp_6", value=6}, Object { name="mDataProp_7", value=7}, Object { name="sSearch", value=""}, Object { name="bRegex", value=false}, Object { name="sSearch_0", value=""}, Object { name="bRegex_0", value=false}, Object { name="bSearchable_0", value=true}, Object { name="sSearch_1", value=""}, Object { name="bRegex_1", value=false}, Object { name="bSearchable_1", value=true}, Object { name="sSearch_2", value=""}, Object { name="bRegex_2", value=false}, Object { name="bSearchable_2", value=true}, Object { name="sSearch_3", value=""}, Object { name="bRegex_3", value=false}, Object { name="bSearchable_3", value=true}, Object { name="sSearch_4", value=""}, Object { name="bRegex_4", value=false}, Object { name="bSearchable_4", value=true}, Object { name="sSearch_5", value=""}, Object { name="bRegex_5", value=false}, Object { name="bSearchable_5", value=true}, Object { name="sSearch_6", value=""}, Object { name="bRegex_6", value=false}, Object { name="bSearchable_6", value=true}, Object { name="sSearch_7", value=""}, Object { name="bRegex_7", value=false}, Object { name="bSearchable_7", value=true}, Object { name="iSortingCols", value=1}, Object { name="iSortCol_0", value=0}, Object { name="sSortDir_0", value="asc"}, Object { name="bSortable_0", value=true}, Object { name="bSortable_1", value=true}, Object { name="bSortable_2", value=true}, Object { name="bSortable_3", value=true}, Object { name="bSortable_4", value=true}, Object { name="bSortable_5", value=true}, Object { name="bSortable_6", value=true}, Object { name="bSortable_7", value=true}]

这是推后

[Object { name="sEcho", value=1}, Object { name="iColumns", value=8}, Object { name="sColumns", value=""}, Object { name="iDisplayStart", value=0}, Object { name="iDisplayLength", value=25}, Object { name="mDataProp_0", value=0}, Object { name="mDataProp_1", value=1}, Object { name="mDataProp_2", value=2}, Object { name="mDataProp_3", value=3}, Object { name="mDataProp_4", value=4}, Object { name="mDataProp_5", value=5}, Object { name="mDataProp_6", value=6}, Object { name="mDataProp_7", value=7}, Object { name="sSearch", value=""}, Object { name="bRegex", value=false}, Object { name="sSearch_0", value=""}, Object { name="bRegex_0", value=false}, Object { name="bSearchable_0", value=true}, Object { name="sSearch_1", value=""}, Object { name="bRegex_1", value=false}, Object { name="bSearchable_1", value=true}, Object { name="sSearch_2", value=""}, Object { name="bRegex_2", value=false}, Object { name="bSearchable_2", value=true}, Object { name="sSearch_3", value=""}, Object { name="bRegex_3", value=false}, Object { name="bSearchable_3", value=true}, Object { name="sSearch_4", value=""}, Object { name="bRegex_4", value=false}, Object { name="bSearchable_4", value=true}, Object { name="sSearch_5", value=""}, Object { name="bRegex_5", value=false}, Object { name="bSearchable_5", value=true}, Object { name="sSearch_6", value=""}, Object { name="bRegex_6", value=false}, Object { name="bSearchable_6", value=true}, Object { name="sSearch_7", value=""}, Object { name="bRegex_7", value=false}, Object { name="bSearchable_7", value=true}, Object { name="iSortingCols", value=1}, Object { name="iSortCol_0", value=0}, Object { name="sSortDir_0", value="asc"}, Object { name="bSortable_0", value=true}, Object { name="bSortable_1", value=true}, Object { name="bSortable_2", value=true}, Object { name="bSortable_3", value=true}, Object { name="bSortable_4", value=true}, Object { name="bSortable_5", value=true}, Object { name="bSortable_6", value=true}, Object { name="bSortable_7", value=true}, Object { name="process", value="fetch"}, Object { name="which", value="all"}]
4

3 回答 3

0

您是否包含了 datatables.js 文件?例如,

<script type="text/javascript" src="/js/dataTables/jquery.dataTables.js"></script>
于 2012-05-16T07:24:33.880 回答
0

除非您实际上将自己的代码放入 jquery.js,否则该错误与您的代码无关。

但是,具有该名称的文件已损坏。您是否修改了该文件中的任何内容?如果没有,只需使用来自http://jquery.com/的新副本恢复它

于 2012-05-16T07:25:49.490 回答
0

使用tableExtraParams.foreach. 而 $.each 的第二个参数,function (k, v)不是那样工作的。它需要两个参数,indexkey。k 将等于 0,1,2,3 等,v 将等于“进程”,“哪个”等。如果要获取键/值对,请使用

var tableXtraPostParams = {
    "process":"fetch",
     "which":"mine"
};
$.each(tableXtraPostParams, function(n, v){
    aoData.push({
        "name": v, 
        "value": tableXtraPostParams[v]
    });
});
于 2012-05-16T21:24:06.043 回答