私はs3バケット内のすべてのオブジェクトの名前を返す私のコードの下のURLの反対側に休憩サービスを持っています。私はそのバケツにいくつのオブジェクトがあるかを教えるシンプルなAlexaスキルを作ろうとしています。私の問題は、http get要求内で、 "this"という用語がhttp get要求の外にあるものと同じものを参照していないということです。どうすればgetリクエストの中で "this"を使うことができますか?あるいは、httpリクエストから "count"変数を返すことができますか?コールバックの中で "this"を使用するには?
"use strict";
var Alexa = require("alexa-sdk");
var Client = require('node-rest-client').Client;
exports.handler = function(event, context, callback) {
var alexa = Alexa.handler(event, context);
alexa.registerHandlers(handlers);
alexa.execute();
};
var handlers = {
'Launch Request': function() {
this.emit('CountItems');
},
'ContentsIntent': function() {
this.emit('CountItems');
},
'CountItems': function() {
var client = new Client();
var count = undefined;
client.get("URL", function (data, response) {
console.log(data['Keys'].length);
count = data['Keys'].length;
});
this.emit(':tell', 'There are ' + count + ' items in your s3 bucket.');
}
};
[コールバック内の正しい\ 'this \'にアクセスするにはどうすればいいですか?](http://stackoverflow.com/questions/20279484/how-to-access-the-correct-this-inside-a -callback) – Pineda