我正在使用带骨干的模糊动作。在我的主干视图中,我有
var EventView = Backbone.View.extend({
tagName: "li",
template: _.template($('#item-template').html()),
events: {
"click .toggle" : "toggleDone",
"dblclick .view" : "edit",
"click a.destroy" : "clear",
"keypress .edit" : "updateOnEnter",
"blur .edit" : "close"
},
initialize: function() {
this.listenTo(this.model, 'change', this.render);
this.listenTo(this.model, 'destroy', this.remove);
},
render: function() {
this.$el.html(this.template(this.model.toJSON()));
this.$el.toggleClass('done', this.model.get('done'));
this.form = this.$(".edit");
this.input = this.$(".edit-title");
this.eventLeaders = this.$('.edit-leaders');
this.eventDescription = this.$('.edit-description');
return this;
},
toggleDone: function() {
this.model.toggle();
},
edit: function() {
this.$el.addClass("editing");
this.form.focus();
},
close: function() {
if (!this.input.val()) {
this.clear();
} else {
this.model.save({
title: this.input.val(),
description: this.eventDescription.val(),
leaders: this.eventLeaders.val().split(/[, ]+/)});
this.$el.removeClass("editing");
}
},
updateOnEnter: function(e) {
if (e.keyCode == 13) this.close();
},
clear: function() {
this.model.destroy();
}
});
在我的 HTML 中,我有:
<script type="text/template" id="item-template">
<div class="view">
<input class="toggle" type="checkbox" <%= done ? 'checked="checked"' : '' %> />
<label><%- title %></label>
<div class="details">
<span class="description"><p><%- description %></p>Leaders:</span>
<% _.each(leaders, function(leader){ %>
<span class="event-leader"> <%= leader %> </span>
<% }); %>
</div>
<a class="destroy"></a>
</div>
<form class="edit">
<input class="edit-title" type="text" value="<%- title %>" />
<input class="edit-description" type="text" value="<%- description %>" />
<input class="edit-leaders" type="text" value="<%= leaders.join(', ') %>" />
</form>
</script>
在我的 CSS 中,我有:
#event-list li.editing .edit {
display: block;
width: 444px;
padding: 13px 15px 14px 20px;
margin: -30px;
}
#event-list li.editing .view {
display: none;
}
#event-list li .edit {
display: none;
}
我遇到的问题是当我在编辑不同的文本框之间切换时会触发模糊事件,但我不知道为什么。即使我使用制表符在文本框之间切换。我不希望这是默认行为。我怎样才能改变这个?