2017-11-21 3 views
0

posts.hbs의 인덱스 값을 delete-post.hbs로 전달한 다음 delete-post.hbs에서 내 delete-post.js로 전달하려고합니다. 기능.한 .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

당신은 페이지를 전달할 수 있습니다 예 : = 연산자는 {{component-name componentProperty=outerProperty입니다. 귀하의 경우 : 또한

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

, 당신은 delete-post.hbs

+0

, 그것은 – AmmarMZ

+0

@AmmarMZ 근무 듣고 행복 FAM 축복이 당신에 parentNodeId-parentNode.id을 변경해야합니다. 내 대답의 왼쪽에있는 눈금 아이콘을 클릭하여 답을 수락 할 수 있습니다. –

+0

posts.hbs에서 직접 parentNodeId를 편집하는 방법을 알고 계십니까? 예를 들어, 1을 추가하려면 : parentNodeId = index + '1' – AmmarMZ