2016-09-18 2 views
0

내가 가진이 코드유성은 일을 onrendered 각

Template.drone.onRendered(function() { 
     var userid = Meteor.userId(); 

     $('.table > tbody > tr').each(function() { 
     var friendid = $(this).find("td:first").html(); 
     var userid = Meteor.userId(); 
     alert('this rendered inside each'); 
     }); 
     }); 

이 템플릿을 테이블 반복 위

Template name="drone"> 
       <table class="table"> 
     <thead> 
      <tr> 
       <th>Id</th> 
       <th>Names</th> 
       <th>Action</th> 
      </tr> 
     </thead> 
     <tbody> 
     {{#each allusers }} 
      <tr> 
       <td class="buttonId">{{_id}}</td> 
       <td>{{profile.name}}</td> 
       <td class="buttonAction">hi</td> 
      </tr> 
      {{/each}} 
     </tbody> 
    </table> 
</template> 

코드를하고 테이블에서 데이터를 유용한 무언가를 행, 즉 각 td의 id.

이 코드가 alert('this rendered inside each');이 실행되지 않는 이유가 궁금합니다.

답변

0

나는 $('.table > tbody > tr')과 일치하지 않습니다.

allusers 반복의 "상위"템플릿 컨텍스트에 있습니다. 이 단계에서 귀하의 tr은 아직 렌더링되지 않습니다.

당신은 userLine이라는 새로운 템플릿을 수행하려고한다 : 이제

{{#each allusers }} 
    {{ >userLine }} 
{{/each}} 

,이 새 템플릿에 onRendered 후크를 사용할 수 있으며, : 당신의 #each에 의해 대체, 그리고

<template name="userLine"> 
<tr> 
    <td class="buttonId">{{_id}}</td> 
    <td>{{profile.name}}</td> 
    <td class="buttonAction">hi</td> 
</tr> 
</template> 

을 당신이 원하는대로 발사해야합니다.