开发者

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.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜