컬렉션에서 모델을 제거하고 제거 이벤트를 실행하려면 어떻게합니까? 나는 people.remove([{ name: "joe3" }]);
을 시도했지만 작동하지 않을 것이다. 이렇게함으로써컬렉션에서 모델 제거 및 화재 제거 이벤트 - backbone.js
var Person = Backbone.Model.extend({
initialize: function() {
console.log(" person is initialized");
},
defaults: {
name: "underfined",
age:"underfined"
}
});
var People = Backbone.Collection.extend({
initialize: function() {
console.log("people collection is initialized");
this.bind('add', this.onModelAdded, this);
this.bind('remove', this.onModelRemoved, this);
},
model: Person,
onModelAdded: function(model, collection, options) {
console.log("options = ", options);
alert("added");
},
onModelRemoved: function (model, collection, options) {
console.log("options = ", options);
alert("removed");
},
});
//var person = new Person({ name: "joe1" });
var people = new People();
//people.add([{ name: "joe2" }]);
people.add([{ name: "joe1" }]);
people.add([{ name: "joe2" }]);
people.add([{ name: "joe3" }]);
people.add([{ name: "joe4" }]);
people.add([{ name: "joe5" }]);
people.remove([{ name: "joe3" }]);
console.log(people.toJSON());
thnaks - 하나 개 더 질문을하시기 바랍니다 - 나는 모델의 속성의 값을 얻는 방법 제거 된 함수 : onModelRemoved : function (model, collection, options) { console.log ("options =", options); 경고 ("removed"+ model.attributes.name + ""+ model.attributes.age + "has been removed"); } –
model.attributes.age가 작동하지 않습니다. –
model.get ('age') –