vista de representación doble
Estoy intentando usar collection.reset () y no obtengo los resultados que estoy esperando en la interfaz de usuario. La respuesta devuelve 2 resultados, que es el esperado. Cuando inspecciono mi colección, siempre me dice que tengo 2 resultados, lo cual también es correcto.
Sin embargo, en mi salida html, simplemente agrega las 2 filas recién recuperadas a la tabla.
initialize: function() {
_.bindAll(this,'buildRows','refreshTable');
this.template = _.template(maintmpl);
this.collection = txnList;
this.collection.bind("all", this.buildRows, this);
this.collection.on("reset", this.refreshTable, this);
this.collection.fetch();
},
events: {
"click #btn" : "refreshTable"
},
render: function() {
this.$el.append( this.template() );
},
refreshTable: function() {
this.collection.reset();
console.log(this.collection.length)
this.collection.fetch();
},
buildRows: function(){
var mainview = this;
_(this.collection.models).each(function(model){
mainview.appendRow(model);
});
},
appendRow: function(model,i) {
var row = txnRow(model);
$('tbody',this.el).append(row.render().el);
}
así que inicialmente, hago esto:
Fila 1
Fila 2
Pero con cada clic del botón que activa refreshTable solo agrega 2 filas más a la tabla:
Fila 1
Fila 2
Fila 1
Fila 2
Fila 1
Fila 2
¿Qué me estoy perdiendo?