【问题标题】:Passing a value from outer for to an inner for using jsRender将值从外部传递到内部以使用 jsRender
【发布时间】:2020-01-26 19:52:55
【问题描述】:

如果我执行以下操作:

{{for Items}}
{{>Id}}
   {{for messages}}
       <div class="myclass">
          {{include tmpl="#myTemplate" /}}
       </div>
   {{/for}}
{{/for}}

然后在我的项目顶部我正确地看到了 Id 的值

如果我现在删除 {{>Id}},因为我已经证明这是我想要的

我现在想将它添加到我的 div 中,使其变为:

<div class="myclass" productid="{{:Id}}">

但是,我没有根据我的 productid 属性设置 Id 值,我已经尝试过 {{:Items.Id}}、{{:parent.Id}} 以及其他一些方法,但均无济于事。

【问题讨论】:

    标签: jsrender


    【解决方案1】:

    您可以通过多种方式获取“父数据”。见https://www.jsviews.com/#parentdata。例如你可以做

    {{for messages ~parentId=Id}}
       <div class="myclass" productid="{{:~parentId}}">
          {{include tmpl="#myTemplate" /}}
       </div>
    {{/for}}
    

    或者您可以通过{{for messages}} 的“数组”视图进入{{for Items}} 的父“项目”视图,使用{{:#parent.parent.data.Id}}。 (见https://www.jsviews.com/#views

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2021-06-04
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2012-10-14
      相关资源
      最近更新 更多