Note that there are some explanatory texts on larger screens.

plurals
  1. POExpress / Node.js - Render page with data
    primarykey
    data
    text
    <p>I have a list of <code>Teams</code> displayed as a list of links on my page, at the moment, I have a textbox....when the link for that <code>Team</code> is clicked, the <code>Key</code> for that <code>Team</code> is taken and sent to the <code>/team/:key</code> route, it searches for the <code>Team</code> by <code>Key</code>, gets the data and sends the data back. If the data was successfully sent back to the JS file then the <code>Team</code> name is output to the textbox.</p> <p>I want to change this, when the link is clicked and the data has been retrieved using <code>Team.findByKey</code> I want to render a new page ('teamDetails') and pass it the data for that <code>Team</code>. This way I can make it so that each link for a <code>Team</code> links to the <code>Team's</code> individual page with their full details on it.</p> <p>Any idea how I would adapt this <code>/team/:key</code> route to do this?</p> <p><code>JS file</code></p> <pre><code>// Setup teamsLink to retrieve Team info for whichever Team was clicked Team.initTeamsLink = function(){ $("a.teamLink").live("click", function(e){ e.preventDefault(); var teamId = ($(this)[0]).getAttribute('id'); $.get('/team/'+teamId, function(response){ if(response.retStatus === 'success'){ var teamData = response.teamData; $('#teamId').val(teamData.key); $('#teamName').val(teamData.name); } else if(response.retStatus === 'failure'){ } }); }); }; </code></pre> <p><code>Route</code></p> <pre><code> app.get('/team/:key', function(req, res) { util.log('Serving request for url [GET] ' + req.route.path); Team.findByKey(req.params.key, function(err, teamData){ if(!err &amp;&amp; teamData){ teamData = teamData; res.json({ 'retStatus' : 'success', 'teamData' : teamData }); } else { util.log('Error in fetching Team by key : ' + req.params.key); res.json({ 'retStatus' : 'failure', 'msg' : 'Error in fetching Team by key ' + req.params.key }); } }); }); </code></pre>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload