我有一个团队列表,并且在团队中有一个任务列表。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。
请有人为我解释一下。