2017-08-03 36 views
1

我用li元素包装我的组件。没关系。但我正在尝试将该操作添加到wrapped元素中。但是出现错误。将action添加到包裹元素的正确方法是什么?如何在EmberJs中添加`action`到组件元素?

任何一个帮助我吗?

我的组件:

<ul> 
     {{#each cardList as |card index |}} 
       {{ 
        cs2i-cardcomponent 
        card=card 
        index=index 
        enableNext='enableNext' 
        tagName="li" 
        {{action "selectCard card index" }}//not works. trying to pass card and index to selected card in actions object in componet.js. 
       }} 
     {{/each}} 
    </ul> 

我的组件JS:

import Ember from 'ember'; 

export default Ember.Component.extend({ 
    tagName:"", 
    firstBalanceType : '', 
    firstBalanceAmount : '', 
    lastBalanceType : '', 
    lastBalanceAmount : '', 
    isSelected : false, 


    actions : { 
     selectCard : function(card,index) { 
      this.set('selectedIndex', index); 
      this.toggleProperty('isSelected'); 
      this.sendAction('enableNext', card); 
     } 
    } 
}); 
+0

它'{{行动 “的SelectCard” 证指数}}' – Lux

+0

还没作品..我不能值传递给操作? – user2024080

+0

@Lux - brase看起来与syntex不同。出现错误'Expected'CLOSE_RAW_BLOCK','CLOSE','CLOSE_UNESCAPED','OPEN_SEXPR','CLOSE_SEXPR','ID','OPEN_BLOCK_PARAMS','STRING ','NUMBER','BOOLEAN','UNDEFINED', 'NULL','DATA','OPEN'' – user2024080

回答

1

这里给您发送该包这是在当前上下文定义selectCard功能selectCard闭合动作。

{{cs2i-cardcomponent card=card index=index enableNext='enableNext' tagName="li" selectCard=(action "selectCard" card index)}} 

代替上述我会鼓励你为PARAMS发送所需的数据组件,从那里你可以在参数发送到数据。

关注ember guides

+0

错误为'ember.debug.js:18008错误:断言失败:在' – user2024080

+0

我已经添加了我的组件js供您参考。 – user2024080

+0

尝试'selectCard =(action“selectCard”卡片索引)' – kumkanillam