¿Puede alguien decirme por qué no funciona lo siguiente por favor? Estoy esperando la alerta para disparar cuando hago clic en el enlacebackbone.js vista simple evento no dispara
<body>
<a class="newnote" href="#">Add new note</a>
</body>
<script>
var note = Backbone.Model.extend({});
var notes = Backbone.Collection.extend({
model: note,
url: '<?= $this->createUrl('/filenotes/api'); ?>'
});
var note_view = Backbone.View.extend({
el: 'table',
});
var Appview = Backbone.View.extend({
el: $('body'),
events: {
"a click" : "showForm"
},
initialize: function(){
//alert('hi');
},
showForm: function(){
alert('hi');
}
});
var v = new Appview();
</script>
Hay una jsFiddle aquí http://jsfiddle.net/neilcharlton/yj5Pz/1/
Gracias por la información adicional. – 32423hjh32423
Mejor sería confiar en el hecho de que Backbone auto-ajustará su 'el' con jQuery cuando sea el momento:' {el: 'body', ...} ', ahora' this. $ El' será el Elemento jQuery que estabas buscando. – rfunduk
+1 rfunduk - la nueva serie v0.9 de backbone hace que sea mucho más fácil de manejar. no hay necesidad de envolver manualmente su el en un selector de jquery ahora, ya que la red troncal lo hace por nosotros –