下面是我的路由器功能,其中我有一个id作为参数。我的问题是如何将id传递到营地视图..谢谢..我尝试了以下..当我在视图中做警报时它说未定义
Router.js
editcampaign :function(id){
$('#content').empty();
require([ 'views/camp' ], function(editcampaign) {
$('#content').html(new editcampaign({campaignID:id}).render().$el);
});
},
Views.js
SM.Views.editCampaign = Backbone.View.extend({myid:id ,
template : _.template(Editcampaigntnpl),
campaignID : 0,
initialize : function() {
_self1=this;
alert(myid); //this says undefined
this.campaign = new Campaign();
this.newscenario = new Newscenarioview();
},
答案 0 :(得分:1)
只需将初始化函数添加为第一行:
initialize : function(options) {
this.campaignID = options.campaignID; // <===
this.myid = options.campaignID;
_self1=this;
alert(myid); //this says undefined
this.campaign = new Campaign();
this.newscenario = new Newscenarioview();
},