2012-09-21 2 views
1

Ember.js 1.0 이전 릴리즈와 Handlebars 1.0.0을 사용 중이며 게시물에 주석 목록을 나타내려고합니다.Ember + Handlebars로 동적 중첩 뷰 처리

내 의견 객체가 이것이다 :

// COMMENT ITEM 
HaBlog.Comment = Em.Object.extend({ 
user:null, 
text:null, 
created: moment().subtract('years', 100), 
createdAgo: function(){ 
    return (this.get('created').fromNow()); 
}.property('created'), 
rating:null, 
replies:[] 

});

<div id="postComments" class="span10"> 
     <h1>Comments</h1> 
     {{#each comments}} 
     <div class="comment"> 
      <small> 
       <span class="commentDate"> 
        {{createdAgo}} 
       </span> 
      </small> 
       <span class="commentText"> 
        {{text}} 
       </span> 
     </div> 
     {{#each comments.replies}} 
     <div class="comment"> 
      <small> 
       <span class="commentDate"> 
        {{createdAgo}} 
       </span> 
      </small> 
       <span class="commentText"> 
        {{text}} 
       </span> 
     </div> 
     {{/each}} 
    </div> 

내 문제는 각 주석이 자신에 대한 의견입니다 응답의 수를 가질 수 있다는 것입니다, 그래서 그들은 더 많은 응답을 가질 수 있습니다

는 그리고 이것은보기에 대한 내 템플릿입니다.

Ember.js와 Handlebars에서 중첩 된 뷰를 확인했지만 모든 응답을 모든 응답을 통해 반복적으로 "트리"방식으로 모든 주석을 표시하는 방식으로 찾지 못하는 것 같습니다.

답변

2

귀하의 질문에 대한 답변과 의견을 정확히 이해하는 데 약간의 어려움이 있습니다. 그러나 아래에서 제안한 내용을 토대로이 문제를 해결할 수 있어야한다고 생각합니다.

Ember.CollectionView을 사용하고 컬렉션보기에서 itemViewClass으로 사용할보기 클래스를 정의하면됩니다. 그래서 itemViewClassCommentView 같은 수 및 템플릿과 같은 어떤 것 :

Comment Text: {{text}} 
Replies: {{view Ember.CollectionView content=replies itemViewClass=HaBlog.CommentView}} 

이것은 당신이 말했듯이, 정말 핸들 바로 처리 할 수없는, 재귀의 문제를 처리 할 수있는 유일한 방법입니다 만 .