在模板中,如何访问外部范围,而在“与”或“范围”范围? [英] In a template how do you access an outer scope while inside of a "with" or "range" scope?
本文介绍了在模板中,如何访问外部范围,而在“与”或“范围”范围?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
在中加入
或范围
时,。
被改变。如何访问调用范围?
When inside a with
or range
, the scope of .
is changed. How do you access the calling scope?
推荐答案
{{with .Inner}}
Outer: {{$.OuterValue}}
Inner: {{.InnerValue}}
{{end}}
$
is documented in the text/template docs:
执行开始时,$被设置为传递给数据参数执行,即点的起始值。
When execution begins, $ is set to the data argument passed to Execute, that is, to the starting value of dot.
这篇关于在模板中,如何访问外部范围,而在“与”或“范围”范围?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文