how to select an element from json array and displ

2020-03-30 07:39发布

问题:

I have a table in DynamoDB local named userGroup. The items are as follows

{
    "Items": [{
        "id": "A004",
        "name": "ACC LR2",
        "userId": ["1", "2", "3", "4"],
        {
            "id": "0001",
            "name": "ABG IT",
            "userId": ["8", "9", "10", "11"]
        }
    }]
}

There are more than 20 lines like this.
This is an entire row

    {
        "id": "A004",
        "name": "ACC LR2",
        "userId": ["1", "2", "3", "4"]
}

this is my routes users.js

router.get('/groups', function (req, res, next) {
    var params = {
        TableName: 'userGroup',
    };
    dynamodb.scan(params, function (err, data) {
        if (err) {
            console.log(err);
        } else {
            console.log("List of Groups: " + console.log(JSON.stringify(data.Items)));
            res.render('groups', {
                _uG: data.Items
            });
        }
    });
});

my group.html is like this

<table>
<thead>
<tr role="row">
<th>Id</th>
<th>User ID</th>
<th>Name</th>
<th>Details</th>
</tr>
</thead>

<tbody>     
<% for(var i = 0; i < _uG.length; i++) { %>                           
<tr>
<td ><%= _uG[i].id.S %></td>            
<td><%= _uG[i].name.S %></td>
<td><a href="/users/groups/group-info?<%= _uG[i].id.S %>">Details</a></td>
</tr>
<% } %>
</tbody>
</table>

this displays values of ID and name and details in a list format in every <td> on the group.html page. NOW when i click on details i should go to group-info page which would display only the all details of only userId from dynamoDB only for that particular row which is selected.

my second routes in users.js

    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)));
                res.render('group-info', {
                    _userD: data.Items
                });
            }
        });
    });

HTML page table 2 for displaying details of data pertaining to is like

<table>
<thead>
<tr role="row">
<th>Id</th>
<th>User ID</th>
<th>Name</th>
<th>Details</th>
</tr>
</thead>

<tbody>     
<% for(var i = 0; i < _uG.length; i++) { %>                           
<tr>
<td ><%= _uG[i].id.S %></td>            
<td><%= _uG[i].name.S %></td>
<td><a href="/users/groups/group-info?<%= _uG[i].id.S %>">Details</a></td>
</tr>
<% } %>
</tbody>
</table>

So what do I do in group-info.js page to display userId of selected <td> of particular row.??

Help is appreciated ..