所以我得到了一个TypeError: invalid 'in‘操作数,WordPress中的一个错误(不确定这是否与它相关),我也不确定代码有什么问题。
下面是有问题的代码:
e_jsonObj = [];
$.each(the_wpcc_posts, function(i, the_wpcc_post) {
var e_post_id = the_wpcc_post[i].ID;
var e_title = the_wpcc_post[i].post_title;
var e_start = the_wpcc_post[i].post_date_gmt;
e_item = {}
e_item ["id"] = e_post_id;
e_item ["title"] = e_title;
e_item ["start"] = e_start;
console.log(e_item);
e_jsonObj.push(e_item);
});这里的任何帮助都是非常感谢的。
发布于 2015-08-12 17:31:19
通过在each循环之前解析数据来尝试这种方法。看起来你正在尝试迭代一个字符串,这导致了这个错误。
e_jsonObj = [];
data = $.parseJSON(the_wpcc_posts); // parsing data
$.each(data, function(i, the_wpcc_post) {
var e_post_id = the_wpcc_post[i].ID;
var e_title = the_wpcc_post[i].post_title;
var e_start = the_wpcc_post[i].post_date_gmt;
e_item = {}
e_item ["id"] = e_post_id;
e_item ["title"] = e_title;
e_item ["start"] = e_start;
console.log(e_item);
e_jsonObj.push(e_item);
});https://stackoverflow.com/questions/31958047
复制相似问题