我试图将一个“动作”从控制器传递给当前模板的孙子组件。但由于某种原因它失败了。谁能让我知道我在这里错过了什么。
MainTemplate's Router Controller
export default class MainTemplateController extends Controller {
field = "userId";
@action
save () {
//save data
}
}
MainTemplate.hbs
<ChildComponent @field={{this.field}} @save={{this.save}} />
ChildComponent.hbs
<GrandChildComponent @field={{this.field}} @save={{this.save}} />
GrandChildComponent.hbs
<button @onClick={{action "doSomething" (readonly @field)}}>Save</button>
export default class GrandChildComponent extends Component {
@action
doSomething(fieldName) {
console.log(fieldName); // logs as "userId"
console.log(this.args.save) // undefined
}
}