else if(content ==='10'){ var picData =yield wechatApi.uploadMaterial('image', __dirname+'/2.jpg',{} ); var media = { articles :[{ title : 'tututu', thumb_media_id : picData.media_id, author : 'pipi', digest: '123', show_cover_pic:1, content:'123', content_source_url:'https://cnodejs.org/' }] } data = yield wechatApi.uploadMaterial('news',media,{}); data = yield wechatApi.fetchMaterial(data.media_id,'news',{}); console.log('data 123 '+data); var items =data.news_item; var news = []; items.forEach(function(item){ news.push({ title:item.title, description : item.digest, picUrl : picData.url, url : item.url }) }) reply = news; }
控制台输出:
{ xml: { ToUserName: [ 'gh_326fbf1082ff' ], FromUserName: [ 'oGZiawGth61Xg19zbUJxwyQrA5_g' ], CreateTime: [ '1468920575' ], MsgType: [ 'text' ], Content: [ '10' ], MsgId: [ '6308965830507425659' ] } } { ToUserName: 'gh_326fbf1082ff', FromUserName: 'oGZiawGth61Xg19zbUJxwyQrA5_g', CreateTime: '1468920575', MsgType: 'text', Content: '10', MsgId: '6308965830507425659' } data 123 [object Object] TypeError: Cannot read property 'forEach' of undefined at Object.exports.reply (/Users/s/Desktop/wechat/weixin.js:94:9)
wechat.js上的代码已参考源代码,但是我想知道是为什么!代码上面的data是传下来的还是创建的对象,这个有点莫名了!console.log('data 123 '+data);输出的是 [object Object]结果对不对?老师求解