[英]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:我有创建 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;
}; };
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.我只是遇到了一些异步函数在我需要它们之前没有返回的问题。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.