javascript - In Meteor how to copy data from inside function to other templates? -
template t1 has js:
if (meteor.isclient) { template.t1.onrendered(function() { var mytasks = { tasks: [ { text: "this task 1" }, { text: "this task 2" }, { text: "this task 3" } ] } } ) ; }
does meteor offer global-variable mechanism allows me copy local mytasks variable global variable or share other templates in way?
if declare variable without var
global client, server, or both (depending on declaration made). example:
client/lib/globals.js
mytasks = [{text: "this task 1"}, {...}];
client/templates/t1.js
template.t1.helpers({ tasks: mytasks });
here, mytasks
global client. note declared variable in file inside of lib
directory loaded before files in other client directories.
if mytasks
accessed via helper, possibility declare global helper this:
template.registerhelper('mytasks', function() { return [{text: "this task 1"}, {...}]; });
and in templates:
{{#each mytasks}} <p>{{text}}</p> {{/each}}
Comments
Post a Comment