【问题标题】:How to access root viewmodel in aurelia inside compose如何在 compose 内访问 aurelia 中的根视图模型
【发布时间】:2017-11-03 02:40:08
【问题描述】:

我在我的应用程序中使用 aurelia compose,如下所示:

<compose view-model="childViewModel" model="{myActivationParameters: ...}"></compose>

如何在childViewModel html 代码中访问父视图模型?

最后我希望能够在childViewModel.html中做到这一点

<span> ${ ParentViewModel.myProperty } and ${ RootViewModel.myOtherProperty } </span>

我正在寻找 aurelia 中的 knockoutJs $root$parent


编辑:我正在使用 aurelia 组合而不是自定义组件。不是重复的。

【问题讨论】:

  • 你试过$parent吗? &lt;span&gt; ${ $parent.myProperty } and ${ RootViewModel.myOtherProperty } &lt;/span&gt;
  • @JessedeBruijne 不是重复的。他使用 compose 元素,而不是自定义元素。

标签: aurelia


【解决方案1】:

在 compose 元素中,您可以访问其父级的上下文。因此,只需执行${myProperty}。如果您在 2 个视图模型中有同名的属性,则无法访问父属性。

在未来的版本中,您需要在 compose 元素中添加属性 inherit-binding-context(请参阅 https://github.com/aurelia/templating-resources/issues/222

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2017-06-24
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2014-03-17
    相关资源
    最近更新 更多