[英]Ember.js - Open modal action won't bubble out of component
我遵循了Ember.js的“ 使用模态对话框” ,并将一个动作处理程序放入ApplicationRoute
。 直到我尝试在组件的模板中使用相同的操作之前,这种方法都很好,在这种情况下,它在控制台中不会执行以下错误: Uncaught Error: Assertion Failed: The
for <appkit@component:user-info::ember451> (49.5) does not have a
Uncaught Error: Assertion Failed: The
目标for <appkit@component:user-info::ember451> (49.5) does not have a
发送method
。
这是一个JSBin演示我的问题。 请注意,索引模板中指定的操作如何调用模式,而组件内部指定的操作却没有。 JSBin的要旨是这样的:
索引模板
<!-- this creates the modal successfully -->
<button {{action "openModal" "modal-login"}}>open a modal (not in a component)</button>
<!-- this component has the same button as above in code, but clicking the button doesnt work -->
{{user-info}}
用户信息组件模板
<button {{action "openModal" "modal-login"}}>open a modal(in a component)</button>
我已经找到了解决方法,但是它很hacky,并向我的组件添加了很多代码。 在组件声明中,我复制了'openModal'操作,并使其通过组件上的已注册操作发送操作, 就像 。
您需要将操作发送到路由器操作。 像这样:
App.UserInfoComponent = Ember.Component.extend({
actions: {
openModal: function(modalName) {
console.log(modalName); this.sendAction('openModal',modalName);
}
}
});
这是具有有效解决方案的jsbin: http ://jsbin.com/fijujikape/1/edit?html,js,console,output
您的解决方法是预期的行为,在组件模板内触发的操作旨在由组件处理。 如有必要,您可以按照指南示例中的操作重定向。
如果要使组件动作针对控制器/路由约定流,则必须将动作设置到组件本身中,而不是在组件子视图中。
{{user-info tagName='button'
action='openModal'
context='modal-login' }}
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.