如何在网上编辑模型的属性,
例如,有<条码> 标准/标准
var Player = Backbone.Model.extend({
defaults: {
id: 0,
name: ,
points: 0
},
initialize: function(){
// irrelevant stuff happening here...
},
rename: function(newName){
this.set({ name: newName });
}
});
缩略语 意见
var PlayerRow = Backbone.View.extend({
tagName: li ,
className: player ,
events: {
click span.score : score ,
blur input.name : rename ,
click div.playername : renderRename
},
initialize: function(){
_.bindAll(this, render , rename );
this.model.bind( change , this.render);
},
render: function(){
var template = Tmpl.render("playerRow", { model : this.model });
$(this.el).html(template);
return this;
},
renderRename: function() {
// i was thinking of switching the DOM into a textfield here
},
rename: function(){
var inpt = $(this.el).find( input.name );
var newName = (inpt.val() != ) ? inpt.val() : no-name ;
this.model.rename(newName);
}
});
一、导 言 1. 罗模板
<script type="text/template" id="playerRow-template">
<% if ( model.get( name ) == ) { %>
<div class="state-edit"><input type="text" class="name" name="name"></input></div>
<% } else { %>
<div class="playername"><%= model.get( name ) %></div>
<% } %>
</script>
或者确定我模式的某些财产,即国家(违约或ed),触发重新招标,而在我的模板中,而不是测试<条码>。
或者说,在我的评论中,我这样说了。 仅将OMD转换成一个投入领域,但我想这是这样做的坏处。 这是否会给已经受到约束的事件造成麻烦? 简称:。
毫无疑问,为电ed形成新观点是最佳方法,因为一想在线编辑,仅就这个名称领域而言,不希望所有参与者模板的其余部分在角色模板和编辑模板中重复。
so, bottomline, my question: what is the best way, to handle inline editing
- a separate view
- inline just appending an input field (don t know if this works well with the bound events)
- having my model hold a state variable for this attribute (would work but sounds weird to have a model hold view related data)