我知道以前曾经问过这个问题,但我找不到合适的答案,即使这很简单:
我的HTML模板中有这个:
<div id="vid"></div>
<button class="mdk-close">x</button>
这在我的观点中:
function (App, Backbone, ArtistVideos, Artistimg, Artistname) {
var ArtistVideoPopup = App.module();
ArtistVideoPopup.View = Backbone.View.extend({
template: 'artistYoutubeVideo',
events: {
"click .mdk-close": "test"
},
test: function() {
alert('dasdasas')
},
beforeRender: function() {
var artistimgCollection = new Artistimg.ArtistimgCollection();
artistimgCollection.artist_id = this.artist_id;
this.insertView('.artistImage', new Artistimg.View({collection: artistimgCollection}));
artistimgCollection.fetch();
var artistnameCollection = new Artistname.ArtistnameCollection();
artistnameCollection.artist_id = this.artist_id;
this.insertView('.artistName', new Artistname.View({collection: artistnameCollection}));
artistnameCollection.fetch();
var artistvideosModel = new ArtistVideos.ArtistVideosModel();
artistvideosModel.artist_id = this.artist_id;
artistvideosModel.video_youtube_id = this.video_youtube_id;
artistvideosModel.fetch();
},
afterRender: function() {
$('ul.acmenu li a.selected').removeClass('selected');
$('ul.acmenu li a.artistVideos').addClass('selected');
var tag = document.createElement('script');
tag.src = "https://www.youtube.com/iframe_api";
var firstScriptTag = document.getElementsByTagName('script')[0];
firstScriptTag.parentNode.insertBefore(tag, firstScriptTag);
var player;
window.onYouTubeIframeAPIReady = _.bind(function() {
player = new YT.Player('vid', {
height: '480',
width: '853',
videoId: this.video_youtube_id,
events: {
onReady: onPlayerReady,
onStateChange: onPlayerStateChange
}
})
}, this);
function onPlayerReady(event) {
event.target.playVideo();
}
var done = false;
function onPlayerStateChange(event) {
// if (event.data == YT.PlayerState.PLAYING && !done) {
// setTimeout(stopVideo, 6000);
// done = true;
// }
}
function stopVideo() {
player.stopVideo();
}
},
});
return ArtistVideoPopup;
}
但事件根本没有发射。有谁知道可能是什么问题?
提前致谢...
答案 0 :(得分:1)
视图中的events
仅绑定到view.el