Ecg.Views.PacienteView = Backbone.View.extend({
events:{
"change #div_pacientes" : "buscar"
},
buscar: function(e){
console.log('test');
buscarHistorial();
},
initialize : function(model){
var self = this;
this.model = model;
this.model.on('change', function(){
self.render();
});
},
render: function(data) {
var pac_select_template = _.template($("#ListaPac_tpl").html(), {
coleccion: window.collections.pacientes.toJSON()
});
$('#div_pacientes').html(pac_select_template);
return this;
}
});
and this is my template
<script id="ListaPac_tpl" type="text/template">
<select id="sel_paciente" name="sel_paciente" >
<% _.each(coleccion,function(paciente) { %>
<option value="<%= paciente.cedula %>">
<%= paciente.nombre %>
</option>
<% }); %>
</select>
</script>
and this is the result:
<label>Pacientes:</label>
<div id="div_pacientes">
<select id="sel_paciente" name="sel_paciente">
<option value="91520731"> Josue </option>
<option value="123456"> joshua </option>
</select>
</div>
<div apellidos="barrios" nombre="joshua" cedula="123456"></div>
<div apellidos="Barrios Rodriguez" nombre="Josue" cedula="91520731"></div>
Question:
- Why underscore or backbone repeat data after div 'div_pacientes' ??
- Why backbone not binding envent change with 'buscar' function ??
Thanks in advance
PD: Happy developer's day