问题描述
当我像这样手动一推一推参数时:aoData.push({"name":"process","value":"fetch"});它运作良好,没有任何错误消息.
When I manually push params one-by-one like this: aoData.push( { "name": "process", "value": "fetch" } ); it works well, without any error message.
但是,现在,我想在脚本顶部声明数组tableXtraPostParams并将此数组的参数逐一推送到aoData
But, now I want to, declare array tableXtraPostParams at the top of script and push one by one this array's params into aoData
这是一段很好的代码
var tableXtraPostParams = {
"process":"fetch",
"which":"mine"
};
$.each(tableXtraPostParams, function(n, v){
aoData.push( {
"name": n,
"value": v
} );
});
但是我在JS日志中收到错误消息
But I'm getting error message in JS log
语法错误,无法识别的表达式:[object Object]
Syntax error, unrecognized expression: [object Object]
我在这里想念什么?
任何建议将不胜感激!
我知道此错误与我的修改有关. (因为当我删除$.each
时,不会出现这样的错误)
I know that this error related with my modification. (Because when I remove $.each
, I don't get any error like this)
这是Aodata在推送之前的外观
Here is what Aodata looks before push
[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"}]
推荐答案
您是否包含了datatables.js文件?例如,
Have you included datatables.js file? For example,
<script type="text/javascript" src="/js/dataTables/jquery.dataTables.js"></script>
这篇关于jQuery替代PHP foreach()的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!