admin管理员组文章数量:1425887
I am rendering a template with Blaze.renderWithData(Template.templateName, { key: value })
;
I can get the value in my template with {{key}}
, but I cannot get the value in my js code.
I have tried
Template.templateName.onCreated( () => {
console.log(Template.instance().key);
});
but the variable is undefined.
I am rendering a template with Blaze.renderWithData(Template.templateName, { key: value })
;
I can get the value in my template with {{key}}
, but I cannot get the value in my js code.
I have tried
Template.templateName.onCreated( () => {
console.log(Template.instance().key);
});
but the variable is undefined.
Share Improve this question asked Dec 28, 2015 at 15:20 JamgreenJamgreen 11.1k32 gold badges122 silver badges232 bronze badges 1- Have you tried using the onRendered callback instead of onCreated?docs.meteor./#/full/template_onCreated: "Callbacks added with this method are called before your template's logic is evaluated for the first time. Inside a callback, this is the new template instance object. Properties you set on this object will be visible from the callbacks added with onRendered and onDestroyed methods and from event handlers." – Jeremiah Commented Dec 28, 2015 at 18:34
3 Answers
Reset to default 5You can use
this.data.key
or
Template.instance().data.key
Cheers
It should be
Template.instance().data['your-key']
If you have doubt about what is the value, put the break on the source code of the chrome developer tools
or firebug
and try to debug. This is the client side, thus all the code will be available
Data passed to template is available on this
in onCreated function,
so this should works:
Template.templateName.onCreated( () => {
console.log(this.key);
});
本文标签: javascriptGet template variable in onCreated in MeteorStack Overflow
版权声明:本文标题:javascript - Get template variable in onCreated in Meteor - Stack Overflow 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1745398093a2656908.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论