如何在 compose 中访问 aurelia 中的根视图模型
How to access root viewmodel in aurelia inside compose
我在我的应用程序中使用 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 组合而不是自定义组件。不是重复的。
在 compose 元素中,您可以访问其父元素的上下文。所以,就做 ${myProperty}
。如果您在 2 个视图模型中具有相同名称的属性,则无法访问父 属性.
在未来的版本中,您需要在撰写元素中添加属性 inherit-binding-context
(参见 https://github.com/aurelia/templating-resources/issues/222)
我在我的应用程序中使用 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 组合而不是自定义组件。不是重复的。
在 compose 元素中,您可以访问其父元素的上下文。所以,就做 ${myProperty}
。如果您在 2 个视图模型中具有相同名称的属性,则无法访问父 属性.
在未来的版本中,您需要在撰写元素中添加属性 inherit-binding-context
(参见 https://github.com/aurelia/templating-resources/issues/222)