我有这个JS功能:
editall: function() {
$('#divedit').removeClass("editing editing2 saving");
$(this.el).addClass("editing editing2 saving");
},
HTML
<script type="text/template" id="item-template">
<li class="<%= done ? 'completed' : '' %>">
<div class="view">
<label class="edit-shopname"><%= shopname %></label>
<label class="edit-shopadress"><%= shopadress %></label>
<button class="all-edit"></button>
<button class="todo-destroy"></button>
</div>
<div id="divedit">
<input class="edit" value="<%= shopname %>">
<input class="edit2" value="<%= shopadress %>">
<button class="save"></button>
</div>
</li>
</script>
它不能正常工作
我不确定这是否是最好的方法, 但我的想法是删除这个“div”(divedit)中的所有类,然后在我按下其他列表项上的编辑按钮时再次添加。 这些项目来自我的数据库,并动态添加。 我想开始编辑新项目并关闭之前添加的所有编辑类。
从parse.com改编的完整对象TODO示例
var ShopView = Parse.View.extend({
//... is a list tag.
tagName: "li",
// Cache the template function for a single item.
template: _.template($('#item-template').html()),
// The DOM events specific to an item.
events: {
"click .todo-destroy" : "clear",
"click .all-edit" : "editall",
},
// The TodoView listens for changes to its model, re-rendering. Since there's
// a one-to-one correspondence between a Todo and a TodoView in this
// app, we set a direct reference on the model for convenience.
initialize: function() {
_.bindAll(this, 'render', 'close', 'remove');
this.model.bind('change', this.render);
this.model.bind('destroy', this.remove);
},
// Re-render the contents of the todo item.
render: function() {
$(this.el).html(this.template(this.model.toJSON()));
this.input = this.$('.edit');
//this.input = this.$('.edit2');
return this;
},
// Toggle the `"done"` state of the model.
toggleDone: function() {
this.model.toggle();
},
// Switch this view into `"editing"` mode, displaying the input field.
editall: function() {
$('#divedit').removeClass("editing editing2 saving");
$(this.el).addClass("editing editing2 saving");
this.input.focus();
},
// Close the `"editing"` mode, saving changes to the todo.
close: function() {
//$(this.el).removeClass("editing");
//$(this.el).removeClass("editing2");
this.model.save({shopname: this.input.val()});
$(this.el).removeClass("editing");};
console.log("close2");
/his.model.save({shopadress: this.input.val()});
$(this.el).removeClass("editing2");};
},
// If you hit `enter`, we're through editing the item.
updateOnEnter: function(e) {
if (e.keyCode == 13) this.close();
},
// Remove the item, destroy the model.
clear: function() {
this.model.destroy();
}
});