首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >在WordPress中获取"TypeError: invalid 'in‘operand a“

在WordPress中获取"TypeError: invalid 'in‘operand a“
EN

Stack Overflow用户
提问于 2015-08-12 14:56:11
回答 1查看 756关注 0票数 1

所以我得到了一个TypeError: invalid 'in‘操作数,WordPress中的一个错误(不确定这是否与它相关),我也不确定代码有什么问题。

下面是有问题的代码:

代码语言:javascript
复制
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);         

});

这里的任何帮助都是非常感谢的。

EN

回答 1

Stack Overflow用户

发布于 2015-08-12 17:31:19

通过在each循环之前解析数据来尝试这种方法。看起来你正在尝试迭代一个字符串,这导致了这个错误。

代码语言:javascript
复制
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);         

});
票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/31958047

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档