我怎样才能访问props
's key
来自嵌套的for
?
{{props object.items}}
{{:key}}
{{for prop.other_items}}
{{:key}} //here I want to print the key from props
我试过了:
{{:key}}
{{:#key}}
{{:#parent.key}}
{{:#parent.parent.key}}
{{:~root.key}}
以下是三种替代方法:
提供key
作为上下文模板变量,因此它可以在{{for}}
block:
{{props object.items}}
{{:key}}
{{for prop.other_items ~outerKey=key}}
Outer key: {{:~outerKey}}
{{/for}}
{{/props}}
提供数据项{{props}}
块({key: ..., prop: ...}
object)作为上下文模板变量,因此它可以在{{for}}
堵塞:
{{props object.items itemVar="~outerProp"}}
{{:key}}
{{for prop.other_items}}
Outer key: {{:~outerProp.key}}
{{/for}}
{{/props}}
逐步浏览父视图(数组视图,然后道具项视图)并获取数据项({key: ..., prop: ...}
目的):
{{props object.items}}
{{:key}}
{{for prop.other_items}}
Outer key: {{:#parent.parent.data.key}}
{{/for}}
{{/props}}
以下是 Matias 对先前问题的相关回复的链接:https://stackoverflow.com/a/31362057/1054484
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)