2013-03-27 3 views
0

다음과 같이 백본 마리오 네트 합성보기가 있습니다.marionette compositeview onfetch

이것은 초기화 방법입니다.

initialize: function(options) { 

     log.debug("Initialize"); 
     this.wizard = options.wizard; 

     this.model = new Feed({ 
      id: options.modelid 
     }); 
     this.modelid = options.modelid; 
     this.collection = new Similar(); 

     this.listenTo(this.model, "change", this.onFetch); 
     this.listenTo(this.model, "reset", this.onFetch); 

     this.collection.fetch({ data: { id: this.modelid }}); 

     this.model.fetch(); 
    }, 

는 이는 본 onFetch 방법

onFetch: function() { 
     log.debug("Fetch"); 

     this.$el.html(this.template(this.model.toJSON()));} 

이며 이는

appendHtml: function(collectionView, itemView, index) { 
     log.debug("appendHtml"); 

     var jsonFeed = itemView.model.toJSON(); 

     if (this.prevFeed === null || jsonFeed.start !== this.prevFeed.start) { 
      var date = new Date(jsonFeed.start); 
      collectionView.$(this.itemViewContainer).append('<div class="day-divider c-color box-center" ><h3>' + moment(date).format('DD MMMM') + '</h3></div>'); 
     } 

     collectionView.$(this.itemViewContainer).append(itemView.el); 

     this.prevFeed = jsonFeed; 
    }, 

내 컬렉션이 HTML 콘텐츠를 덮어 쓰는 onFetch 함수 비운의 append 방법이다. 이것은 내 기록입니다.

DEBUG - Initialize 
DEBUG - Render 
DEBUG - appendHtml 
DEBUG - appendHtml 
DEBUG - appendHtml 
DEBUG - Render 
DEBUG - Fetch 

어떤 생각입니까? 어떻게 해결할 수 있습니까?

답변

0

onFetch의 onRender instad를 사용하지 않는 이유는 무엇입니까? onRender는 렌더링이 완료되면 내용을 표시하는 이미 포함 된 함수입니다.

참고 : 모든 것이 렌더링되었을 때 작업을 수행하는 onShow도 사용할 수 있습니다.

+0

몇 가지 생각을 한 후에 나는이 방법을이 결론에 도달했다. $ el.html (this.model.toJSON())); }는 render 메소드에 있어야합니다 (백본 메소드를 대체). –

관련 문제