2017-11-21 13 views
0

posts.hbsのインデックス値をdelete-post.hbsに渡し、次にdelete-post.hbsからmy delete-post.jsに渡そうとしています関数。1つの.hbsファイルから別の.hbsファイルに値を渡す方法

posts.hbs

<br> 
<h2> Blog Posts </h2> 
<ul> 
{{#each model as |onePost index|}} 

    <li id = {{index}}>{{onePost.title}} {{delete-post}} 
    </li><br> 

{{/each}} 
</ul> 

{{add-new-post}} 

削除-post.hbs

<a class="ui red button" {{action 'deletePost' parentNode.id `}}>Delete</a>` 

削除-post.js

import Component from '@ember/component'; 

export default Component.extend 
({ 
    actions: 
    { 
    deletePost(input) 
    { 
     alert(input); 
    } 
    } 

}); 

答えて

1

あなたはPを渡すことができますオペレータによって=オペレータ{{component-name componentProperty=outerPropertyのようなarameter。あなたのケースでは:

{{#each model as |onePost index|}} 
    <li id = {{index}}>{{onePost.title}} {{delete-post parentNodeId=index}} 
    </li><br> 
{{/each}} 

また、あなたがFAMを祝福あなたのdelete-post.hbs

+0

parentNodeIdparentNode.idを変更する必要があり、それはそれを聞いて幸せ – AmmarMZ

+0

@AmmarMZを、働いていました。私の答えの左側にある目のアイコンをクリックして答えを受け入れることができます。 –

+0

posts.hbsで直接parentNodeIdを編集する方法を知っていますか?たとえば、次のように番号1を追加したいとします。parentNodeId = index + '1' – AmmarMZ

関連する問題