2017-10-07 9 views
1

나는 Google 스프레드 시트에있는 데이터를 Alexa에게 알리기 위해 노력하고 있습니다. http.get() 메소드 대신 google-spreatsheet node.js 모듈을 사용하고 있습니다. 여기 람다 함수에서 emit() 속성을 정의하는 방법

이 실행 결과에서 내 의도 기능

'GetPainterIntent': function() { 
     // spreadsheet key is the long id in the sheets URL 
var doc = new GoogleSpreadsheet('1K-dl08g8s27TgF5yMGv_Q5tBbkpRpGWrt3RkUB2mVKk'); 
var sheet; 

async.series([ 
    function setAuth(step) { 
    // see notes below for authentication instructions! 
    var creds = require('./creds.json'); 
    // OR, if you cannot save the file locally (like on heroku) 
    /* 
    var creds_json = { 
     client_email: ' ', 
     private_key: ' ' 
    } 
     */ 
    doc.useServiceAccountAuth(creds, step); 

    }, 
    function getInfoAndWorksheets(step) { 

    doc.getInfo(function(err, info) { 
     console.log('Loaded doc: '+info.title+' by '+info.author.email); 
     sheet = info.worksheets[0]; 

     //console.log('sheet 1: '+sheet.title+' '+sheet.rowCount+'x'+sheet.colCount); 
     this.emit('ask:', 'Do you want'+sheet.title+' '+sheet.rowCount+'x'+sheet.colCount); 
     step(); 
    }); 

    } 

], function(err){ 
    if(err) { 
     console.log('Error: '+err); 
    } 
}); 

    } 

입니다 : 실패 로그, 내가 할 중요한 것들 중 하나는 발광가 정의되지 않은 내부에서이 ...

{ 
"errorMessage": "RequestId: 79ed1bc9-aaee-11e7-878b-5fe3ebd777ae 
Process 
exited before completing request" 
} 

TypeError: Cannot read property 'emit' of undefined 
at getInfoAndWorksheets (/var/task/index.js:51:9) 
at /var/task/node_modules/async/dist/async.js:3853:24 
at replenish (/var/task/node_modules/async/dist/async.js:946:17) 
at iterateeCallback 

는 속성입니다 ? 아니면 어떻게 방출의 속성을 정의합니까? 아니면 내가 잘못 읽었습니까?

답변

1

나는 비동기 시리즈를 사용하기 때문에 코드를 작성한 방법을 잃어 버렸다고 생각한다. 상단에 var self=this과 같은 줄을 사용하여 this을 저장 한 다음 self.emit을 대신 사용하십시오.