簡體   English   中英

Ember.js-開放模式操作不會冒出組件

[英]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' }}

http://jsbin.com/takatoyi/2/edit

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM