Javascript 在Ember中,我是否可以向组件提供输入标记而不破坏表单?
我在想也许我在函数中发现了一个bug 我想要实现的是,表单的一个组件,如果需要的话,我会生成额外的输入标记。我的示例更复杂,但我在中复制了“bug” 基本上,我有一个组件: 表单组件/模板.hbs 正如你所看到的,它在旋转中不起作用。(应将表格下方的文本更新为您的输入) 但是如果我将输入Javascript 在Ember中,我是否可以向组件提供输入标记而不破坏表单?,javascript,ember.js,ember-cli,Javascript,Ember.js,Ember Cli,我在想也许我在函数中发现了一个bug 我想要实现的是,表单的一个组件,如果需要的话,我会生成额外的输入标记。我的示例更复杂,但我在中复制了“bug” 基本上,我有一个组件: 表单组件/模板.hbs 正如你所看到的,它在旋转中不起作用。(应将表格下方的文本更新为您的输入) 但是如果我将输入{{input value=name placeholder='name'}}从application/template.hbs移动到组件,它会工作: 更新的表单组件/模板.hbs 这是一个bug,还是我在这里遗
{{input value=name placeholder='name'}}
从application/template.hbs
移动到组件,它会工作:
更新的表单组件/模板.hbs
这是一个bug,还是我在这里遗漏了一些明显的东西?如果您想在表单组件中设置值,可以使用如下内容:
//form-component/template.hbs
{{#form-component
action="controllerAction" as |myForm|}}
{{input value=myForm.name placeholder='Name'}}
{{/form-component}}
//application/template.hbs
<form {{action 'componentAction' on='submit'}}>
{{yield this}}
<button type="submit">Submit</button>
</form>
//表单组件/template.hbs
{{#形式组件
action=“controllerAction”作为| myForm |}
{{input value=myForm.name占位符='name'}
{{/form component}
//应用程序/模板.hbs
{{产生这个}}
提交
这不是一个bug。您的输入值将在您声明的组件或控制器中设置。如果在application/template.hbs中创建输入,则该值将在模板控制器中设置。如果您在组件中创建它,值将在组件的形式中设置。您知道在使用时是否可以这样做以获得多个产量吗?我的意思是像{{yield body this}}
{{#form-component
action="controllerAction"}}
{{input value=name placeholder='Name'}}
{{/form-component}}
<form {{action 'componentAction' on='submit'}}>
{{yield}}
{{input value=name placeholder='Name'}}
<button type="submit">Submit</button>
</form>
{{#form-component
action="controllerAction"}}
{{/form-component}}
//form-component/template.hbs
{{#form-component
action="controllerAction" as |myForm|}}
{{input value=myForm.name placeholder='Name'}}
{{/form-component}}
//application/template.hbs
<form {{action 'componentAction' on='submit'}}>
{{yield this}}
<button type="submit">Submit</button>
</form>