Formatting US zip codes with leading zeros in a Meteor helper -
i have collection in meteor has imported csv file zip code field. problem when print out document query, print zip 04191 4191.
.... {{#each query}} <p>{{zip}</p> {{/each}} .... i'd need like:
.... {{#each query}} <p>{{zip.tostring()}</p> {{/each}} ....
here's generic zip code helper:
template.registerhelper('formatzip',function(zip){ var pad="00000"; return (pad+zip).slice(-5); // 5 digit zips only! }); you can use template in app with:
{{formatzip zip}} assuming zip contains zip code wish format.
with props https://stackoverflow.com/a/9744576/2805154 - answer merely reformulates answer meteor.
Comments
Post a Comment