0

私のコンストラクターでは、別のクラス関数をサブスクライブします。subscribe 内からクラス メソッド show を呼び出すにはどうすればよいですか。

var MemPortfolio = MemPortfolio || {};
MemPortfolio.Portfolio = function (contentid, thumbclass, featuredid) {
    this.thumbClass = thumbclass;
    this.featuredId = "#" + featuredid;
    var that = this;
    //subscribe to menutile click
    $.subscribe("/menutile/click/portfolio", function (tilename) {
        that.Show();
    });
};

MemPortfolio.Portfolio.prototype.Show = function () {
    alert("show");

}

私のドキュメントの準備ができました: /// ///

$(document).ready(function () {
    //check exists?
    var tilemenu = new MemTileMenu.Menu("menu", "menuitem", "contentarea");
    var portfolio = new MemPortfolio.Portfolio("contentarea", "thumb", "");
});

私はこれを機能させました-

/// <reference path="jquery-1.7.1.js" />
/// <reference path="jquery.ba-tinypubsub.js" />
var MemPortfolio = MemPortfolio || {};
MemPortfolio.Portfolio = function (contentid, thumbclass, featuredid) {
    this.thumbClass = thumbclass;
    this.featuredId = "#" + featuredid;    
};

MemPortfolio.Portfolio.prototype = {

    show: function () {
        alert("show");
    },
    subscribe: function () {
        var that = this;
        $.subscribe("/menutile/click/portfolio", function (tilename) {
            that.show();
        });
    }

Doc.Ready はこちら:

/// <reference path="tilemenu.js" />
/// <reference path="portfolio.js" />
$(document).ready(function () {
    //check exists?
    var tilemenu = new MemTileMenu.Menu("menu", "menuitem", "contentarea");
    var portfolio = new MemPortfolio.Portfolio("contentarea", "thumb", "");
    portfolio.subscribe();
});
    }

ありがとう。オタクの人

4

2 に答える 2

0

これは機能します。

  /// <reference path="jquery-1.7.1.js" />
    /// <reference path="jquery.ba-tinypubsub.js" />
    var MemPortfolio = MemPortfolio || {};
    MemPortfolio.Portfolio = function (contentid, thumbclass, featuredid) {
        this.thumbClass = thumbclass;
        this.featuredId = "#" + featuredid;    
    };

    MemPortfolio.Portfolio.prototype = {

        show: function () {
            alert("show");
        },
        subscribe: function () {
            var that = this;
            $.subscribe("/menutile/click/portfolio", function (tilename) {
                that.show();
            });
        }
    Doc.Ready here:

    /// <reference path="tilemenu.js" />
    /// <reference path="portfolio.js" />
    $(document).ready(function () {
        //check exists?
        var tilemenu = new MemTileMenu.Menu("menu", "menuitem", "contentarea");
        var portfolio = new MemPortfolio.Portfolio("contentarea", "thumb", "");
        portfolio.subscribe();
    });
        }
于 2013-03-06T04:33:13.500 に答える
0

で置き換えMemPortfolio.Portfolio.prototypeてみてくださいMemPortfolio.prototype.Portfolio

于 2013-03-05T19:01:53.927 に答える