Backbone,Underscore模板绑定事件

时间:2013-09-13 14:41:58

标签: javascript events backbone.js binding underscore.js

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;
    }
});

这是我的模板

<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>

这就是结果:

<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>

问题:

  1. 为什么在div'div_pacientes'??
  2. 之后强调或骨干重复数据
  3. 为什么主干没有绑定envent改变'buscar'功能??
  4. 提前致谢

    PD:开发者日快乐

0 个答案:

没有答案