我的 DynamoDb 本地数据库架构具有以下项目。
{"Items": [{ "id": "A004","name": "ACC LR2","userId": ["1","2","3","4"], {"id": "0001","name": "ABG IT","userId": [ "8","9","10","11"]}}]}
我只想选择用户 ID 并使用 nodejs 将其列出到我的 html 页面中。我该怎么办?
///// MY entire code
router.get('/groups/group-info', function(req, res, next) {
///////////////////////////////////////
console.log("id "+req.query.id);
var params = {
TableName: 'userGroup',
};
console.log("PARAMS: "+JSON.stringify(params));
dynamodb.scan(params, function(err, data) {
if (err) {
console.log(err);
}
else {
// console.log("These are Groups: "+ console.log(JSON.stringify(data.Items)));
console.log("User DETAILS: "+ console.log(JSON.stringify(data.Items) ));
// for each
function getUserId(obj){
result = []
obj.Items.forEach( function(item, i){
result.push(item.userId);
});
return result;
}
function getUserIdAll(obj){
result = []
obj.Items.forEach( function(item, i){
result = result.concat(item.userId);
});
return result;
}
console.log( getUserId(data) );
console.log( getUserIdAll(data) );
// for each end
res.render('group-info',{_userD : data.Items});
}
});
/////////////////////////////////
/* res.render('group-info', { title: '' });*/
});
//////Entire code end
这就是我的整个代码的运行方式,我做错了什么?