Reputation: 709
Data is on the client generated and saved in a local collection:
ListLocal = new Mongo.Collection(null);
let seed = [{
name: "A",
value: 1
}, {
name: "B",
value: 2
}, {
name: "C",
value: 3
}];
if (ListLocal.find().count() === 0) {
ListLocal.forEach(function(entry) {
ListLocal.insert(entry);
});
};
Then it is passed on the client to the server for further processing:
Template.home.events({
"click .btn-process": function(event) {
event.preventDefault();
let localData = ListLocal.find({}).fetch();
Meteor.call("processData", localData);
}
});
The server accepts the data and passes it to a server-side Method that does some stuff with it, eg. doubles all values of the passed Objects:
Meteor.methods({
processData(localData) {
calculateDouble(localData);
}
});
calculateDouble(localData) {
// ...
return calculatedData;
}
Now i want to display this calculatedData client-side without saving it in a server-side database.
Question: How can i pass this data to the client?
Upvotes: 0
Views: 111
Reputation: 20788
Simply return the data from the method:
Meteor.methods({
"processData": function(localData) {
return calculateDouble(localData);
}
});
calculateDouble(localData) {
// ...
return calculatedData;
}
To call the method in the event:
Template.home.events({
"click .btn-process": function(event) {
event.preventDefault();
let localData = ListLocal.find({}).fetch();
Meteor.call("processData", localData, function(error, result){
//handle what you need to do with the result here.
});
}
});
Upvotes: 2