0
서버에서 백본 모델 (엄밀히 말하면 컬렉션)을 가져온 후 서버에서 반환 된 값을 가로 채기 전에 찾고 수정하는 방법을 찾고 있습니다 계속. 나는 이런 식으로 할 수 있다고 생각한다.백본 가져 오기 성공 콜백을 사용하여 초기화보기 전에 데이터 변경
SessionController.prototype._initPages = function() {
return App.pages.fetch({
reset: true,
success: function(model, response, options) {
//modify the contents of response
}
};
그리고 내 수정 사항은보기를 초기화하는 데 사용 된 모델에 반영 될 것이다.
그러나 백본 원본을보고 있었는데 뭔가 잘못 이해했을 수 있습니다.
fetch: function(options) {
options = options ? _.clone(options) : {};
if (options.parse === void 0) options.parse = true;
var success = options.success;
var collection = this;
options.success = function(resp) {
var method = options.reset ? 'reset' : 'set';
collection[method](resp, options); //this line updates the model
if (success) success(collection, resp, options); // my success callback
collection.trigger('sync', collection, resp, options);
};
wrapError(this, options);
return this.sync('read', this, options);
}
필자는이 기능을 사용하는 방법을 오해하고 있다고 가정하고 있지만 두 개의 주석 처리 된 줄을 전환해야하는 것처럼 보입니다.
내 모델이되기 전에 서버 응답을 수정하려면 어떻게해야합니까?
+1 을 필요에 따라 당신은 당신의 데이터를 수정하기 위해
parse
기능을 무시할 수 있다고 생각. 이것이 바람직한 방법입니다. –