나는 modifyCollection 이벤트 dblclick과 관련된 기능입니다 jeditable를 사용하여 내 컬렉션을 편집 할 수 있습니다. 나는 다음과 같은 코드를 가지고있다.jeditable 함수 내부에서 컬렉션을 전달하는 방법은 무엇입니까?
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);
}
});
idee는 모델을 업데이트 한 다음 jeditable을 사용하여 컬렉션을 업데이트한다. in place 편집은 잘 작동하지만 문제는 컬렉션에 함수를 전달할 수 없다는 것입니다. 내 컬렉션의 모든 변경 사항을 로컬에 저장하고 나중에 서버로 보내려고합니다. 여기서 내가 뭘 잘못하고 있니?
글쎄, 내가 말할 수있는 한가지는'onblur()'함수의'this'가'this' 콜렉션을 가리키고 있지 않다는 것입니다. 'modifyCollection()'함수 안에'var self = this;'를 추가하고'onblur()'에서'this.collection'을'self.collection'으로 변경하십시오. – jmk2142
고마워요. 그것은 작동합니다! – Amateur
@orangewarp : 그 의견은 의심 스러울 정도로 대답과 같습니다. –