gpt4 book ai didi

javascript - Backbone : Can't remove a view when call method remove()

转载 作者:行者123 更新时间:2023-12-03 11:10:40 30 4
gpt4 key购买 nike

我尝试删除包含在 map 中渲染的制造商的 View 。当我单击按钮时,事件 click .ver 被激活,但没有任何反应,并且我收到以下错误:Uncaught TypeError: undefined is not a function。我不知道我做错了什么。

我的代码:

ev.views.Home_Eventos = Backbone.View.extend({
initialize: function(map){
this.template = _.template(ev.templateLoader.get('home_list_eventos'));
this.map = map;
//console.log(this.map);
this.render(this.map);
},

events: {
'click .ver' : 'teste'
},

teste: function(){
ev.views.Markers.remove();
},

render: function(map){
var that = this;
that.map = map;
var imagens = new ev.models.ImagemCollection();
imagens.fetch({
success: function(){
that.$el.html(that.template({imagens: imagens.models}));
var marcadores = imagens.models;
setTimeout(function() {
that.local(that.map);
var marcadores = new ev.views.Markers(that.map);
}, 0);
return that;
}
});
}

});

ev.views.Markers = Backbone.View.extend({
initialize: function(map){
this.map = map;
this.render(this.map);
},

render: function(map){
var that = this;
var imagens = new ev.models.ImagemCollection();
imagens.fetch({
success: function(){
var marcadores = imagens.models;
setTimeout(function() {
_.each(marcadores, function(marcador){
var myLatlng = new google.maps.LatLng(marcador.get('latitude'),marcador.get('longitude'));
var marker = new google.maps.Marker({
position: myLatlng,
map: that.map,
});

});
}, 0);

return that;
}
});
}

});

最佳答案

您需要保留对要删除的 View 的引用。例如,您有:

var marcadores = new ev.views.Markers(that.map);

您可以通过执行以下操作来保存 View 上的引用:

that.marcadores = new ev.views.Markers(that.map);

然后在你的事件处理程序中,

teste: function(){
this.marcadores.remove();
},

这会破坏您创建的 Marker View ,但可能不会清除该 View 管理的 Google map 标记。

关于javascript - Backbone : Can't remove a view when call method remove(),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/27610869/

30 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com