2013-01-25 3 views
0

내 백본 기능에는 필터 방법이 없으므로 대신 'this. $ el.append()', 'this. $ el.html()'을 사용하기로 결정했습니다. 하지만 대체 html()이 작동하지 않습니다. 나는 새로운 컬렉션으로 구멍보기를 재연하는 것이 좋을 것이라고 생각했습니다.백본이 html로 대체되지 않음

또한 $ el.empty()를 만들려고했지만 작동하지 않습니다 ... 어떻게 부모로부터 기존 요소를 지우고 새로운 생성 요소를 추가 할 수 있습니까? 내 코드는

:

renderBoard:function(item){ 
      var singleView = new taskListPhraseI.oneView({model:item}), 
// after this, i need to make parent of the element should be empty... 
      board = this.$el.append(singleView.render()), 

      newBoard = board.find('.indBoard:last'); 
      this.positionBoards(newBoard); 
     }, 

내가 어떻게 이것을 달성 할 수 있습니까? 당신이보기를 렌더링 할 때 다음

views = window.views || {}; 

views.ExampleView = Backbone.View.extend({ 

    initiliaze: function(){ 
     // do some stuff 
    }, 

    render: function(){ 

     $(this.el).html("<YOUR HTML GOES HERE></YOUR HTML GOES HERE>"); 

     // return yourself as simple to chain access to your "el" 
     return this; 
    } 

}); 

을 다음과 같이보기 설정을 손 전에 모든 다른 뷰를 제거하려면

답변

1

그래서,

renderView: function(item) 
{ 
    var test=new views.ExampleView({ 
     model:item 
    }); 

    // this should replace the elements contents with the views html above 
    $(this.el).html(test.render().el); 
} 

만약 뭔가를 가고 싶어 당신은 여전히 ​​문제가 있습니다. 어쩌면 'this'가 문맥을 잃어 버렸고, 더 이상 클래스를 참조하지 않고, 렌더링 할 때 그 값이 무엇인지 디버깅 할 수 있습니다.

희망하는 사람

관련 문제