简体   繁体   English

Meteor.js:如何从模板中获取模板的名称?

[英]Meteor.js : How to get the name of a Template from the Template?

Lets say I have a definition of a template in a html file. 可以说我在html文件中有模板的定义。

<template name="myTemplate">

Now in javascript I want to get the value that is name in template by referencing the Template itself to avoid typing mistakes and to allow intellij ide ctrl clicking of the template to take me to the template. 现在,在javascript中,我想通过引用模板本身来获取模板中名称的值,以避免键入错误,并允许对模板进行智能提示单击以将我带到模板。

I want something like. 我想要类似的东西。

let stringValueOfTemplateName = Template.myTemplate.name

Instead of having to do 不必做

let stringValueOfTemplateName = "myTemplate"

Is there any way to access the name? 有什么办法可以访问这个名字?

尝试

let stringValueOfTemplateName = Template.instance().view.name.replace('Template.', '');
Template.captureView.viewName.replace('Template.',''))

要么

Template.instance().view.name.replace('Template.',''))

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM