将数据从dynamodb.scan传递到外部

时间:2018-10-02 12:07:27

标签: javascript node.js amazon-web-services amazon-dynamodb

我试图将在dynamodb.scan中获得的值传递到dynamodb.scan块之外,但我得到的是空列表,原因可能是因为它的异步功能仍然会获得我想要的输出

  function contactMethod(contact){
        dynamodb.scan(params, function(err, data){
            const teamMembers = [];
            if(err){
                console.log(err);
            }else{
                const items = data.Items.map((dataField) =>{
                    if(dataField.name.S === member){
                        return {name: "" +dataField.name.S, email: "" + dataField.email.S};
                    }
                });
                items.forEach(function(item){
                    if(item !== undefined){
                        teamMembers.push(item.name, item.email);
                    }
                })
            }
            console.log(teamMembers); //I am getting the desired o/p over here
        })
    }

    function dispatch(intentRequest, callback) {
            const intentName = intentRequest.currentIntent.name;
            if (intentName == 'SOMETHING'){
                sessionAttributes = intentRequest.sessionAttributes;
                slots = intentRequest.currentIntent.slots;
                team = slots.team;
                contact = slots.contact;
                member = slots.teammember;
                params = {
                    TableName: 'team'
                };
                if(contact === 'email' || contact === 'phone'){
                    contactMethod(contact);
                }
                console.log(teamMembers);//getting empty list over here 
                callback(close(sessionAttributes, 'Fulfilled',
                    {'contentType': 'PlainText', 'content': `Okay, Here are the details you requested ${teamMembers}`}));

            }
            throw new Error(`Intent with name ${intentName} not supported`);
        }

1 个答案:

答案 0 :(得分:0)

您是否已将其发布在DynamoDB论坛上?:https://forums.aws.amazon.com/forum.jspa?forumID=131。我建议也将其张贴在这里。

此外,我刚刚在该论坛中搜索了字符串“ dynamodb.scan”,以下是所有结果:https://forums.aws.amazon.com/search.jspa?mbtc=06c784cf811d4e21aeabfd436e0558e611b4e9ab02ac3273ca75d232a2b55be6&objID=f131&q=dynamodb.scan&x=0&y=0。如果该结果集被忽略,只需进入论坛并在此处的搜索框中搜索“ dynamodb.scan”即可。