我有一个团队列表,在团队中有一个任务列表。 JSON数据如下所示:
{
{"teamId":38,
"teamName":"Analytics",
"tasks":{
{
"taskId":93561,
"taskName":"Analytics Country Report"
}
}
},
{"teamId":32,
"teamName":"Client Service - Team Beaumont",
"tasks":{
{
"taskId":93558,
"taskName":"Project Management"
}
}
},
{"teamId":34,
"teamName":"Copy",
"tasks":{
{
"taskId":93580,
"taskName":"Copy"
}
}
},
{"teamId":48,
"teamName":"Engineering - Team LZ",
"tasks":{
{
"taskId":93573,
"Front-end Development"
},
{
"taskId":93562,
"taskName":"Quality Control"
}
}
}
}
我的观点:
View.SchedulingTask = Backbone.Marionette.ItemView.extend({
template: 'resource-planning/scheduling/templates/_scheduling-task',
className: 'scheduling-task-handle',
initialize: function() {
var _this = this;
App.vent.on( "scheduling:task:remove:" + _this.model.get('taskId'), function(){
console.log('Task removed' + _this.model.get('taskId');
_this.trigger('task:remove');
_this.remove();
})
},
});
View.SchedulingTeam = Backbone.Marionette.CompositeView.extend({
template: 'resource-planning/scheduling/templates/_scheduling-team',
itemView: View.SchedulingTask,
initialize: function(){
this.collection = _this.model.get('tasks');
this.on('itemview:task:remove', function(itemView){
console.log("Team: task removed: " + _this.model.get('teamId'));
// If the collection is empty, I need to remove the team as well
});
}
});
在另一个视图中的某处我触发了以下事件:我希望删除任务93558。 App.vent.trigger( “调度:任务:除去:93558”);
我期望发生的事情是:
'任务已删除93558'
“团队:已删除任务:32”
但是看到的是:
'任务已删除93558'
“团队:已删除任务:48”
看起来像itemView事件冒泡没有冒泡到正确的CollectionView。
请允许有人为我阐明这一点。