当我尝试连接两个包含两个不同 BackboneJS 视图的模块时,我遇到了问题。
在 RequireJS 的这个模块中包含一个主干视图。我需要在这个模块中,参考另一个模块中的另一个主干视图。我修改了代码以使其更简单
define (["jquery","backbone","collections/controlSearchCollection","views/currentPlaylist","jqueryUI"], function($, Backbone, controlSearchMusic, currentPlaylist){
var searchModule = Backbone.View.extend({
el: "#containerSearch",
initialize: function () {
this.collection = new controlSearchMusic();
},
events:{
"dblclick li":"select"
},
select: function(element){
var trackJSON ={};
trackJSON["id"]= "playCloud_"+$(element.target).attr("id");
currentPlaylist.collection.add(trackJSON); <--- Here is where this error
}
});
return searchModule;
});
在这里,我的另一个 RequireJS 模块包含一个主干JS 的视图。我需要从第一个模块添加到 JSON。
define (["jquery","backbone","collections/controlCurrentPlaylistCollection","jqueryUI"], function($, Backbone, controlCurrentPlaylist){
var currentPlaylist = Backbone.View.extend({
el: "#currentPlaylist",
initialize: function(){
this.collection = new controlCurrentPlaylist();
this.collection.on("add", this.executeFunction, this);
},
executeFunction: function(song){
alert(song.toSource());
}
});
return currentPlaylist;
});
这两个模块在 app.js 中实例化
有人可以帮助我吗?谢谢!