简体   繁体   中英

Backbone.js Views not rendering

Something bizarre is going on. I have code which creates a Backbone.js View, except it never gets rendered, however if i run it in console it works:

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;

};

and heres how it's called:

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

when i manually run the above line in console, it works brilliantly. but it doesnt load in my script.

I just had some issues with Asynchronous functions not returning before I needed them.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM