2016-11-16 26 views
2

組件操作完全觸發。組件中的Ember.js發送數據到另一個組件的操作

import Ember from 'ember'; 

export default Ember.Component.extend({ 
    actions: { 
     searchField: function() { 
     console.log('searchField'); 
     this.sendAction('searchField'); 
     } 
    } 
}); 

路由不會被觸發。

import Ember from 'ember'; 

export default Ember.Route.extend({ 
    actions: { 
     searchField: function() { 
     console.log('ROUTE'); 
     } 
    } 
}); 

把手

{{input key-up='searchField' searchField=(action "searchField")}} 

我花了這麼多時間,這個我開始與Ember.js失去興趣,因爲我已經根據文檔也試過,但我得到了相同的結果。 http://emberjs.com/api/classes/Ember.Component.html#method_sendAction

任何幫助將有所幫助。

謝謝;

回答

2

sendAction不會達到route。 你有兩個選擇,

  1. 在控制器定義searchField功能,並從那裏你可以路由功能this.send('searchField')

  2. 直接打電話從組件路線,對於這個插件ember-route-action-helper

ember install ember-route-action-helper

參考answer獲取更多信息。 玩弄 - Sample Twiddle

+1

我更喜歡'ember-route-action-helper'。如果您不使用它,那麼您的組件必須知道它們是否放置在另一個組件的模板或路徑模板中。 – ykaragol

+0

@ykaragol如何讓組件知道它被放置在控制器中 –

+0

@kumkanillam我投這個正確的,因爲它的工作原理和給我我的解決方案,但是需要注意的是,它只有在component.js動作是空的。 –

相關問題