I am working on a backbone app at the moment, and I have hit a bit of wall. I have collection that looks like this,
r {length: 3, models: Array[3], _byId: Object, constructor: function, model: function…}
_byId: Object
_events: Object
_listenerId: "l40"
length: 3
models: Array[3]
__proto__: s
As you can see the collection has 3 models, and an example of the model is below,
0: r
_changing: false
_events: Object
_pending: false
_previousAttributes: Object
attributes: Object
complete: false
completed_by: "0"
completed_by_name: null
end_date: false
files: r
id: "7693"
is_owner: false
item_active_task_count: 0
item_description: "sdsadasdasd"
item_files: r
item_id: "7693"
item_name: "First Item (1)"
item_tasks: r
item_type: null
numFile: 8
parent_id: null
progress: "0"
subItems: r
sub_items: Array[2]
tasks: r
__proto__: Object
changed: Object
cid: "c3"
collection: r
counter: 5
id: "7693"
__proto__: s
Within the model above I another collection called item_files, this collections looks like this,
_byId: Object
length: 8
models: Array[8]
0: r
1: r
2: r
3: r
4: r
5: r
6: r
7: r
length: 8
__proto__: Array[0]
__proto__: s
and a model within this collection looks like this,
models: Array[8]
0: r
_changing: false
_events: Object
_listenerId: "l48"
_pending: false
_previousAttributes: Object
attributes: Object
creator: "Me"
creator_id: "14"
download_url: "http://test.dev/projects/download/696d6167655f31322e4a5047/698/14"
file_created: "2014-06-12 00:00:00"
file_hex: "696d6167655f31322e4a5047"
file_parent_id: "7694"
file_parent_type_id: "7694"
id: "9011"
is_owner: 1
last_modified: "2014-06-12 00:00:00"
panel_name: "image_12.JPG"
project_id: "698"
size: "1.76 MB"
thumb_url: null
timeago: "a day ago"
user_type: ""
viewer_url: "http://test.dev/projects/viewer/698/696d6167655f31322e4a5047"
__proto__: Object
changed: Object
cid: "c12"
collection: r
id: "9011"
__proto__: s
What I am doing at the moment, is working on some delete functionality, I have a function that builds a container, and then lists models from the item_files
collection, the view gets build like this,
addItems: function() {
this.model.get('items').each(this.loadItem, this);
//bind the expander
$('.expander').unbind('click').click($.initExpanders.expander);
},
loadItem: function(item) {
if(item.get("item_parent_id") == undefined) {
var item_parent_id = item.get("item_id");
}
//item.set({"numFile" : item.get('item_files').length});
var itemView = new app.ItemView({
model: item,
collection:item.get('item_files')
});
this.$el.find('.wrapper').append(itemView.render(item).el);
if(item.get("subItems") !== undefined ) {
if(item.get("subItems").length > 0) {
if(item.get("subItems").length == 1) {
this.$el.find(itemView.el).find('.sub-item-count').text(item.get("sub_items").length + " Sub Item");
} else {
this.$el.find(itemView.el).find('.sub-item-count').text(item.get("sub_items").length + " Sub Items");
}
}
}
//itemView.addFilesWrapper(item);
//itemView.addFiles();
var itemFilesFilter = new app.FilesFilter({
collection: item.get('item_files'),
model: item
});
this.$el.find('article[data-item-id='+item.get('id')+'] .tab-content.files:first').html(itemFilesFilter.render().el);
var that = this;
item.get('files').each(function(file){
var itemFileListItem = new app.FileListItem({
model: file,
collection: item.get('item_files'),
});
//console.log(that.$el.find('article[data-item-id='+item.get('id')+'] .tab-content').append(itemFileListItem.render().el));
that.$el.find('article:first[data-item-id='+item.get('id')+'] .image-grid:first').append(itemFileListItem.render().el);
});
},
so above lists out the models from the item collection, I thought I would able to listen to item collection for a change and then run any functionality I need from that, as change consists of and edit addition or deletion.
However if I remove a model from the collection the change event does not seem to trigger what is the problem?