【问题标题】:How can I access a parent client-side-collection from a child template in Meteor-Blaze?如何从 Meteor-Blaze 中的子模板访问父客户端集合?
【发布时间】:2020-03-25 12:45:46
【问题描述】:

我有一个子模板,我希望能够在其中操纵父级的客户端集合。子模板是可重用的组件,不能有全局集合。不幸的是 Template.parentData(n) 对我不起作用。通过视图访问集合也不合适,因为父集合所在的级别因用例而异(我想将层次结构中父集合的上下文/索引动态地提供给子模板) .这是我的代码结构的示例。

<template name="parentTemplate">
  <form id="accessGroupsPutForm">
    {{#let accessGroupSelected=accessGroupSelected}}
      ...
      <div class="form-group row">
        <label for="accessGroupsPutUsers" class="col-lg-2 col-form-label">
          Access Rules
        </label>

        {{> childTemplate config=configAssignElements}}
      </div>
    {{/let}}
  </form>

现在我想从我的孩子访问父上下文中的集合,可能在 Template.childTemplate.onRendered() 或 .onCreated() 函数中。

有没有人可以解决这个问题?

【问题讨论】:

    标签: meteor meteor-blaze mongo-collection


    【解决方案1】:

    有一个很棒的氛围包可以处理绑定和许多其他类似的事情:https://atmospherejs.com/manuel/viewmodel。 使用它,你可以轻松做到this.parent().runUpdateMethod(params)

    【讨论】:

      猜你喜欢
      • 2016-03-07
      • 2016-01-09
      • 2016-03-04
      • 2014-05-12
      • 1970-01-01
      • 2016-06-10
      • 1970-01-01
      • 1970-01-01
      • 2017-07-02
      相关资源
      最近更新 更多