【发布时间】:2012-09-03 07:50:20
【问题描述】:
我想使用 jeditable 编辑我的收藏,其中 modifyCollection 是与事件 dblclick 关联的函数。我有以下代码:
initialize : function(options) {
view.__super__.initialize.apply(this, arguments);
this.collection = this.options.collection;
this.render();
},
render : function() {
var template = _.template(tpl, {
collectionForTemplate : this.collection ,
});
this.el.html(template);
return this;
},
modifyCollection : function (event){
$('#name').editable(function(value, settings) {
return (value);
}
,
{ onblur: function(value) {
this.modelID=event.target.nameID;
this.collection = this.options.collection;
console.log("This Collection is: " + this.collection); //Shows : undefined
//
this.reset(value);
$(this).html(value);
return (value);
}
});
想法是更新模型,随后通过 jeditable 更新集合。就地编辑工作正常,但问题是,我无法将集合传递给函数。我想在本地保存对我的集合的所有更改,并在以后将它们发送到服务器。我在这里做错了什么?
【问题讨论】:
-
嗯,我可以评论的一件事是,
this在您的onblur()函数中没有指向this集合。尝试在modifyCollection()函数中添加var self = this;,然后在onblur()中将this.collection更改为self.collection -
@orangewarp:那条评论看起来有点像一个答案,而且是正确的答案。
-
是的...不是吗? ;-)
标签: backbone.js jeditable