나는 저장 기능이 작동하는 그룹을 만들 때 순간에 앱을 만들고 있습니다. 모델이 컬렉션에 추가되고 데이터베이스에 저장되지만, 편집하려면 내가 만든 그룹은 방금 편집 한 데이터와 PUT 요청이 실행되는 대신 새 모델을 저장 (및 POST 요청)하여 저장합니다. 여기 내 저장 기능이 있습니다 - 기존 모델을 편집 할 때 PUT 요청을 실행하지 않는 이유가 있습니까? 모델이 편집되는 대신 새 행을 만듭니다.
GroupModalHeaderView.prototype.save = function(e) {
var $collection, $this;
if (e) {
e.preventDefault();
}
$this = this;
if (this.$("#group-name").val() !== "") {
$collection = this.collection;
if (this.model.isNew()) {
this.collection.add(this.model);
}
return this.model.save({ name: this.$("#group-name").val()}, {
async: false,
wait: true,
success: function() {
var modelID = $this.model.get('id');
return this.modal = new app.GroupModalView({
model: $this.collection.get(modelID),
collection: $this.collection
});
}
});
}
};
이
내 모델 기본값이 저장하기 전에 여기Group.prototype.defaults = {
user_id: "",
name: "New Group",
email: "",
url: "",
telephone: "",
mobile: "",
fax: "",
people: ""
};
이
this.model
의 CONSOLE.LOG입니다
Group {cid: "c116", attributes: Object, _changing: false, _previousAttributes: Object, changed: Object…}
_changing: false
_events: Object
_pending: false
_previousAttributes: Object
email: ""
fax: ""
mobile: ""
name: "New Group"
people: ""
telephone: ""
url: ""
user_id: ""
wait: true
__proto__: Object
attributes: Object
changed: Object
cid: "c116"
collection: GroupCollection
id: 189
__proto__: ctor
감사합니다. 제 편집을보실 수 있습니까? 문제가 있습니까? – Udders
저장 요청을 보내기 전에 모델에서'id'를 설정해야합니다 –
하지만 성공 콜백에서 console.log ($ this.model.get ("id")를 사용하면 모델 ID를 볼 수 있습니다 ? – Udders