0
我有兩個視圖文件views.js和views2.js。按鈕單擊views.js call.On views.js有一個按鈕,需要觸發views2.js 。但問題是,在按鈕上單擊views2.js 不起作用。如何從backbone.js視圖調用視圖
我寫了一些代碼。 在views.js
define(["backbone"], function(Backbone) {
var UserView = Backbone.View.extend({
tagName: "div",
render: function(){
this.$el.html(this.model.get("desc") + "<button id='btn2' class='btn btn- primary'>Next Page</button>");
return this;
}
});
var NextPageView = Backbone.View.extend({
events: {
'click': 'firstquestion'
},
render: function(){
return this;
},
firstquestion: function(){
//to solve circular dependency
require(['routes'],function(routes){
var router = routes.pageRouter;
router.navigate('view', {trigger: true});
});
}
});
var views2 = require("views2");//should I call views2 here
var np2 = new views2.NextPageView2({el: $("#btn2")});
return {
UserView: UserView,
NextPageView: NextPageView
};
});
在views2.js
define(["backbone"], function(Backbone) {
var UserView2 = Backbone.View.extend({
tagName: "div",
render: function(){
this.$el.html(this.model.get("desc") + "<button id='btn3' class='btn btn-primary'>Next Page</button>");
return this;
}
});
var NextPageView2 = Backbone.View.extend({
events: {
'click': 'secondquestion'
},
render: function(){
return this;
},
secondquestion: function(){
require(['routes2'],function(routes2){
var router = routes2.pageRouter2;
router.navigate('view', {trigger: true});
});
}
});
return {
UserView2: UserView2,
NextPageView2: NextPageView2
};
});
嘗試調用代碼 - 'var views2 = require(「views2」); var np2 = new views2.NextPageView2({el:this。$(「#btn2」)});'view of view.js。看看它是否工作 – deven98602