mongodb - Creating fields based on what's returned, meteor pub/sub -
probably bad title, don't know how precisely describe this.
template.body.helpers({ messages: function () { return messages.find({}, { sort: {createdat: -1} }); } });
this code have. on client side, takes
{{#each messages}} <span class="text"> {{messagetext}} </span> {{/each}}
each message contains "text" , "username".
how go about, in "return messages" part, modifying returns?
so like
template.body.helpers({ messages: function () { messages.find().foreach(function(thismsg){ messagetext = slugify(thismsg.messagetext) }; } });
get messages, modify fields , return them. perhaps in subscriptions instead? please help.
you can pass message in helper , can modify message , pass template this.
your template code.
{{#each messages}} <span class="text"> {{slugifymessage text}} </span> {{/each}}
you helper code.
template.body.helpers({ messages: function () { return messages.find({}, { sort: {createdat: -1} }); } slugifymessage: function(messagetext){ return slugify(messagetext); } });
please make sure text passing slugifymessage same name database mentioned have 2 field named username , text, took text can replace doc field want modify.
Comments
Post a Comment