Я пытаюсь запустить событие click
, но оно не работает. Может быть, кто-то может видеть что-то, что я не могу.
ConnectionView = GlobalView.extend({
tagName: 'div',
events: {
"click .social-links": "check"
},
initialize: function() {
this.render();
this.model.bind("change", this.render);
},
render: function() {
// Compile the template using underscore
var template = _.template($("#connection-template").html(), this.model.toJSON());
// Load the compiled HTML into the Backbone "el"
$(this.el).html(template);
},
check: function(e) {
e.preventDefault();
alert("woot");
}
});
Вот шаблон, который он тянет:
<script id="connection-template" type="text/template">
<a id="link-<%= alt %>" class="social-links" href="<%= url.replace('||state||', state).replace('||timestamp||', time) %>">add <%= name %></a>
</script>
Вот представление, которое помещает ConnectionView в DOM:
ConnectionsView = GlobalView.extend({
tagName: 'div',
initialize: function(){
this.collection.bind("reset", this.render, this);
},
render: function(){
var $connections = $("<div class='external-accounts'>");
this.collection.each(function (model) {
var conn = new ConnectionView({model: model});
$connections.append(conn.el);
});
// Compile the template using underscore
var template = _.template($("#connections-template").html());
// Load the compiled HTML into the Backbone "el"
$(this.el).html(template({
connectionsList: $connections.outer()
}));
},
destroy: function() {
this.constructor.__super__.destroy.apply(this);
}
});
ConnectionView
el
в DOM? - person Esailija   schedule 26.06.2012.outer
— это пользовательский метод, который я добавил в jQuery — он просто создает оболочку<div>
и извлекает из нее.html
. Причина, по которой я это сделал, заключалась в том, что .html захватил только то, что было в текущем элементе, но не все. - person xil3   schedule 27.06.2012