typescript - Update a property using parent template's event handlers
问题描述
I am trying to design some components using FASTElement. However, I couldn't pass a dynamic property from parent to a child component. In my design, I have two FAST templates as follows,
childCompTemplate.ts
const myChildComponent = () => html<ChildModel>`<div class=${x => x.customTheme!.someSpecialClassName}`>
<!-- some stuff -->
</div>`
parentCompTemplate.ts
const myParentComp = () => html<ParentModel>`<div @mouseEnter=${x => x.customTheme!.handleMouseEnterEvent()} @mouseExit=${x => x.customTheme!.handleMouseExit()}`>
<my-child-component :customTheme=${x => x.customTheme} />
</div>`
CustomTheme.ts
public class CustomTheme {
@observable someSpecialClassName: string;
/* Some other props and functions */
public handleMouseEnter() {
this.someSpecialClassName = "foo";
}
public handleMouseExit() {
this.someSpecialClassName = "bar";
}
I referenced customTheme property in the model files,
ParentModel.ts <= this is an interface
...
customTheme?: CustomTheme;
...
ChildModel.ts
...
@observable customTheme?: CustomTheme;
...
However, when I triggered the event, I saw no change in the child component's div class. Could you please help me to understand which point that I am missing?
Thanks for the help!
TL;DR I want to update a property when some specific event is fired on the parent template. However, changes are not affecting the child.
解决方案
这种情况肯定会奏效。我突然想到的一件事是您的活动名称。你有@mouseEnter
和@mouseExit
。我认为您的事件没有触发,因此状态的变化实际上并没有发生。尝试将这些更改为@mouseenter
and @mouseleave
。
推荐阅读
- node.js - Nodebeats -> MongoDB 连接使用 mongodb+srv 并且不使用 admin db 仍然抛出未经授权的错误
- javascript - 查询 firestore 中的文档集合并将其保存在变量中始终返回空
- google-apps-script - 类型错误:getCreators() 不是函数
- pdftk - pdftk无法打开文件
- r - 无法提取我在 Panoply 中看到的 R 中的 netcdf 变量
- python - IndexError:标量变量的索引无效,我已尝试使用其他简单函数使用相同的公式,但它不起作用
- c# - C# Azure DevOps Git:无法推送新目录
- ibm-cloud - 如何在 IbmCloud 中部署应用程序?
- git - Azure Devops - 从另一个组织导入 git repo 链接到另一个项目中的工作项
- javascript - 在 Redux 的反应中更新数组中对象中的值