2011-08-15 6 views
1

기괴한 일이 일어나고 있습니다. 난 내가 콘솔에서 실행 작동하지만 경우, 렌더링됩니다 결코 제외하고는 Backbone.js보기를 생성하지 코드를 가지고 :Backbone.js보기가 렌더링되지 않습니다.

function createBookingsView($container, roomID){ 
var BookingsView = Backbone.View.extend({ 
    el    : $container, 
    initialize  : function(){ 
          console.log("derp"); 

          _.bindAll(this, "addOne", "addAll", "render"); 

          this.bookings = new Bookings(); 
          this.bookings.bind("change", this.addOne); 
          this.bookings.bind("refresh", this.addAll); 
          this.bookings.bind("all", this.render); 

          this.bookings.fetch({data : {"room" : roomID}}); 
          console.log(this.bookings.get(1)); 
         }, 
    addAll   : function(){ 
          this.bookings.each(this.addOne); 
         }, 
    addOne   : function(booking){ 
          var view = new BookingView({model:booking}); 
          $(this.el).append(view.render().el); 
         }, 
    render   : function(){ 
          $(this.el).html(""); 
          this.addAll(); 
         } 
}); 
return new BookingsView; 

};

과를 heres은 호출 방법은 다음과 같습니다 내가 수동으로 콘솔 위의 줄을 실행할 때

window.LEFT_BOOKINGS = createBookingsView($("#timetable-a .bookingContainer"), room.id); 

, 그것은 훌륭하게 작동합니다. 하지만 내 스크립트에로드되지 않습니다.

+0

그리고 document.ready 등에서 호출됩니다. – chris

+0

"pagebeforeshow"이벤트에서 호출되도록 JQueryMobile을 사용하고 있습니다. _window.LEFT_BOOKINGS_가 할당되어 콘솔에서 액세스 할 수 있기 때문에 호출되는 것을 알고 있습니다. 콘솔에서 이와 같이 입력하지 않으면보기가 렌더링되지 않습니다. ** window.LEFT_BOOKINGS = createBookingsView ($ ("# timetable-a .bookingContainer"), 2); ** – sw00

+0

좋아요, 조사를 해봤는데 createBookingsView를 호출 할 때 아직 $ ("# timetable-a .bookingContainer")가 DOM에 없다는 것을 알 수 있습니다. 그래서 아마 별개의 문제 일 겁니다. – sw00

답변

0

비동기 함수가 필요하기 전에 반환하지 않는 문제가 생겼습니다.

관련 문제