그래서 테이블 뷰 (상위) 및 행 뷰 (하위)이 있습니다.백본 컬렉션 모델 자체 복제
this.listenTo(this.files_collection, "change", this.renderList);
App.Views.file_manager_item
var File_manager_item = Backbone.View.extend({
tagName: 'tr',
initialize: function() {
this.listenTo(this.model, "change", this.render);
},
template: Template7.compile(document.getElementById("fm_item_template").innerHTML),
events: {
"click .check": "toggleCheck",
},
toggleCheck: function() {
this.test = !this.test;
this.model.set({
"checked": this.test
});
},
render: function() {
console.log(this.model)
var context = this.model.toJSON();
this.el.innerHTML = this.template(context);
return this.$el;
},
});
된다
는이 코드
addOne: function (model, base) {
var view = new App.Views.file_manager_item({model: model});
base.append(view.render());
},
renderList: function() {
var _this = this;
var collection = this.files_collection;
document.getElementById("content").innerHTML = this.templates.table(this.context);
this.$files = $(document.getElementById('files'));
collection.each(function(model) {
_this.addOne(model, _this.$files);
});
},
와 renderList
에 의해 해고를 모든 행을 추가
및 첫 번째 실행 복귀 toggleCheck
기능
child {cid: "c3", attributes: Object, ...}
child {cid: "c3", attributes: Object, ...}
...
...
...
...
child {cid: "c11", attributes: Object, ...}
모든 모델 변경 후 두 번 실행
child {cid: "c3", attributes: Object, ...}
...
...
...
...
child {cid: "c11", attributes: Object, ...}
후 콘솔로, 콘솔
child {cid: "c3", attributes: Object, ...}
의 새로운 아이 추가 왜 모델이 복제되고 있습니까?
그것은 좋은 질문, 미안해 할 필요가 없다는 사실, 질문 "X 죄송합니다"를 포함해서는 안 그런 다음 목록보기 때문에 그것은 무관하다;) –