backbone-localstorage 플러그인을 사용하여 백본 예제를 기반으로 작은 응용 프로그램을 만듭니다.백본 localstorage "url"속성 또는 기능을 지정해야합니다.
난 항상 오류가 새로운 모델에 대한 데이터를 저장할 때 "A는"URL "속성이나 기능을 지정해야합니다"
여러 시뮬 주제를 읽은 후 나는 아직도를 찾을 수 아니에요 원인.
모델 :
directory.models.EmployeeCollection = Backbone.Collection.extend({
localStorage: new Backbone.LocalStorage("EmployeeCollection"),
model: directory.models.Employee,
store: directory.utils.store,
findByName: function(key) {
this.reset(this.store.findByName(key));
}
});
뷰 :
directory.views.newEmployeeView = Backbone.View.extend({
tagName: "div",
initialize: function() {
this.template = _.template(directory.utils.templateLoader.get('new-employee'));
},
events: {
"click .save": "saveEmployee"
},
render: function(eventName) {
$(this.el).html(this.template(this.model.toJSON()));
return this;
},
saveEmployee: function(event){
this.model.set({
firstName:$('#newFirstName').val(),
lastName:$('#newLastName').val(),
title:$('#newTitle').val(),
city:$('#newCity').val(),
officePhone:$('#newOfficePhone').val(),
cellPhone:$('#newCellPhone').val(),
email:$('#newEmail').val()
});
this.model.save();
window.history.back();
return false;
}
});
뷰의 모델 속성이 이미 컬렉션의 멤버입니까? 보기에서 모델 속성을 설정하는 방법을 보여줄 수 있습니까? –
모델이 아직 컬렉션에 없습니다. 새로운 것입니다. \t 새 인스턴스 : function() {this.slidePage (new directory.views.newEmployeeView ({model : new directory.models.Employee()}). render());} – Hazaart
... 인스턴스화해야하는지 확실하지 않습니다. 컬렉션 및 이것을 수행 할 위치는 무엇입니까? – Hazaart