7
estoy consiguiendo el error:Backbone - objeto rinda ha ningún método 'aplicar'
object render has no method apply for the below code.
Cuál puede ser el motivo? La página html no contiene ningún código excepto el enlace para el javascript.
¿qué debo hacer para eliminar el error?
(function($) {
window.Book = Backbone.Model.extend({});
window.Library = Backbone.Collection.extend({
model: Book
}); // end of Collection
window.LibraryView = Backbone.View.extend({
el: $('body'),
events: {
'click button#btn_add': 'btn_add'
},
initialize: function() {
$(this.el).append("View initialized");
_.bindAll(this, 'render', 'btn_add');
this.collections = new Library();
this.collections.bind('add', 'render', this);
this.startingDisplay();
},
startingDisplay: function() {
$(this.el).append("<input type='text' id='t1' /><button id='btn_add'>Add</button>");
},
btn_add: function() {
book = new Book({
title: "first"
});
alert("Name : " + book.get('title'));
this.collections.add(book);
},
render: function() {
alert("render called");
},
}); // end of LibraryView
libraryview = new LibraryView();
})(jQuery);
muchas gracias, funciona de maravilla! – user1305989
¿por qué debería devolver "esto" en la función de renderizado? Qué hace ? – user1305989
Entonces es encadenable, por lo tanto puedes hacer 'myView (someModel) .render(). El'. En la vista principal, puede que no sea tan interesante, pero resulta útil cuando tiene una vista para, digamos, un ContactItem. –