Backbone.js视图不渲染

Backbone.js Views not rendering

本文关键字:视图 js Backbone      更新时间:2023-09-26

奇怪的事情发生了。我有代码创建一个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;

};

它的名字是这样的:

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

当我在控制台中手动运行上述行时,它运行得非常好。

我刚刚遇到了一些异步函数在我需要它们之前没有返回的问题。