1

下面是我的路由器功能,其中我有一个 id 作为参数。我的问题是如何将 id 传递到营地视图..谢谢..我尝试了以下..当我在视图中发出警报时,它说未定义

路由器.js

editcampaign :function(id){
        $('#content').empty();
        require([ 'views/camp' ], function(editcampaign) {
            $('#content').html(new editcampaign({campaignID:id}).render().$el);
        });
    },

视图.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();
        },
4

1 回答 1

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();
},
于 2013-07-11T10:53:49.300 回答