Backbone.js 主干.木偶项目视图事件冒泡问题
我有一个团队列表,团队中有一个任务列表。JSON数据如下所示:Backbone.js 主干.木偶项目视图事件冒泡问题,backbone.js,backbone-events,Backbone.js,Backbone Events,我有一个团队列表,团队中有一个任务列表。JSON数据如下所示: { {"teamId":38, "teamName":"Analytics", "tasks":{ { "taskId":93561, "taskName":"Analytics Country Report" } } }, {"teamId":32, "teamName":"Client
{
{"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
});
}
});
我的观点:
{
{"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
请有人帮我解释一下。如果你这样做会发生什么代码>而不是
var\u this=this代码>?是的,我知道你可能不再研究这个了,但我想知道这与这个是如何绑定的。或者,您可能需要在View.SchedulingTeam.initialize
的主体中添加一条或另一条语句。