我有一个带有占位符和按钮的组件。每当单击此按钮时,我都想实例化一个子组件并将其添加到占位符 div。这就像在按钮单击时添加行。我如何实现这种行为。
这是伪代码。
MainCompoent.hbs
<div id="placeHolder> </div>
<button onClick={{this.clickAdd}}> Add </button>
MainCompoent.js
@action
clickAdd() {
//How to initialize Row Component and add to the placeHolder
}
RowComponent.hbs
<div>
<input name>
<input age>
</div>
我尝试了类似的方法,但没有按预期工作。
MainComponent.js
@action
addCondition (){
document.getElementById("placeholder").innerHTML += `<RowComponent/>`;
}