怎么做?我搜索了 Stack Overflow,找到了一个类似的结果,但它不起作用。
这是我的代码:
var Player = Backbone.Model.extend({
defaults: {
//some variables
},
//creating audio element
setAudio: function(ogglink, mp3link){
//code, that works
}
});
var Playlist = Backbone.Collection.extend({
model: Player
});
var MyPlaylist = new Playlist([
//some songs here
]);
var OneSongView = Backbone.View.extend({
//added some 'template' and 'el' code
initialize: function () {
this.model.bind("change", this.render, this);
},
render: function (eventName) {
$(this.el).html(this.template(this.model.toJSON()));
this.model.setAudio(this.model.get("ogglink"), this.model.get("mp3link"));
return this;
},
events: {
//declaration of some events
},
//event functions
});
var AppRouter = Backbone.Router.extend({
//router code
});
var app = new AppRouter();
Backbone.history.start();
如果我添加类似timeupdate
:的事件somefunc
,它将无法正常工作,如果我在此处添加代码,则会出现错误 :(