Reputation: 707
Okay so for example I have this collection named "Results"
.
I'll query Results.find()
;
This will give the value of {foo: 'hello_world'}
;
and now I want to replace the _ with a " " (white space) using javascript before I return it to the template. Any idea how?
Upvotes: 0
Views: 1296
Reputation: 75945
You can use a transform. You just alter your Results.find()
to include it as an option.
var transform = function(doc) {
doc.foo = doc.foo.replace(/_/g, ' ');
return doc;
}
return Results.find({}, {transform: transform} );
Upvotes: 3
Reputation: 8013
This should work in your helper:
return Results.find().fetch().map(function(res) {
res.foo = res.foo.replace('_', ' ');
return res;
});
Upvotes: 1