Hi,
I’m having two issues:
1st:
I’m retrieving JSON data using a HTTP.call. With the retrieved data, I’m populating a table. But during the populating of the table, another function has to be called for retrieving a new result, based on the value of a specific JSON object. This data should be retrieved from a mongoDB collection. How should I do this?
What I’m having now is:
api.js
Template.API.events({
'submit .dosubmit': function(event) {
event.preventDefault();
var ID = event.target.sub.value;
var getRows = event.target.rows.value;
if(ID == "") {
alert('Er is geen subscriber ID opgegeven!');
} else {
Session.set('disabled', 'disabled');
console.log("Entered ID is: " + ID);
console.log("Entered Rows is: " + getRows);
Meteor.call('checkCalls', ID, getRows, function(error, result) {
if(error){
console.log(error);
Session.set("JSONError", true);
Session.set('disabled', '');
} else {
var json = JSON.parse(result.content);
Session.set('disabled', '');
Session.set("JSONResult", json._embedded['nested:array']);
var Calls = json._embedded['nested:array'];
Session.set("TotalCount", json.total_count);
}
});
}
}
});
api.html
<table class="table">
<thead>
<th>Call ID</th>
<th>Caller</th>
<th>Callee</th>
<th>Zone</th>
<th>Startdatum en tijd</th>
<th>Duur</th>
<th>Kosten</th>
</thead>
<tbody>
{{#if $.Session.equals 'JSONError' true}}
<tr>
<td colspan="4">Fout bij ophalen van gegevens!</td>
</tr>
{{else}}
{{#each $.Session.get 'JSONResult'}}
<tr>
<td>{{id}}</td>
<td>{{source_cli}}</td>
<td>{{destination_user_dialed}}</td>
<td>{{zone_id}}</td>
<td>{{start_time}}</td>
<td>{{duration}}</td>
<td>{{source_customer_cost}}</td>
</tr>
{{else}}
<tr>
<td colspan="4">Geen gegevens gevonden</td>
</tr>
{{/each}}
{{/if}}
<tr>
<td colspan="4">Totaal aantal rijen: {{$.Session.get 'TotalCount'}}</td>
</tr>
</tbody>
</table>
The value in column Zone should retrieved while populating this table, based on the value of {{zone_id}}.
2nd:
As can be seen in the code from api.js above, I’m storing the result in a Session instead of a variable. I can store it in a variable, but then #each doesn’t do anything. So:
This works
{{#each $.Session.get 'JSONResult'}}
But this doesn’t
{{#each Calls}}
What is preferred in this scenario? Sessions or variables?