Warning: file_get_contents(/data/phpspider/zhask/data//catemap/0/backbone.js/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Javascript 这个按钮不见了吗?_Javascript_Backbone.js_Addthis - Fatal编程技术网

Javascript 这个按钮不见了吗?

Javascript 这个按钮不见了吗?,javascript,backbone.js,addthis,Javascript,Backbone.js,Addthis,在我的主干应用程序中,我使用了addthis按钮。 我的问题是,当我将应用程序导航到一条路线并返回主路线时,按钮(fb、twitter、share)消失了。但是,如果我刷新页面,那么按钮就会显示出来,任何帮助都将不胜感激 提前谢谢 代码如下所示 var mainProfileView = Backbone.View.extend({ el:"#inner", template: _.template($('#main-profile-tmpl').html()), ini

在我的主干应用程序中,我使用了
addthis
按钮。 我的问题是,当我将应用程序导航到一条路线并返回主路线时,按钮(fb、twitter、share)消失了。但是,如果我刷新页面,那么按钮就会显示出来,任何帮助都将不胜感激

提前谢谢

代码如下所示

var mainProfileView = Backbone.View.extend({
    el:"#inner",
    template: _.template($('#main-profile-tmpl').html()),
    initialize: function(){
        _.bindAll(this, "render");
        this.render();
    },
    events:{
        'click .profile-details' : 'detailedProfile',
        'click .credibility' : 'credibility',
        'click #moreReviews': 'moreReview',
        'click #moreReferences' : 'moreReferences'
    },
    detailedProfile:function(){
        router.navigate('/detailedProfile',true);
    },
    credibility : function() {
        router.navigate('/credit',true);
    },
    moreReview : function() {
        router.navigate('/moreReviews',true);
    },
    moreReferences : function() {
        router.navigate('/moreReferences',true);
    },
    render: function(){ 
        this.$el.html(this.template());
    }
});

var creditView = Backbone.View.extend({
    el:"#inner",
    template: _.template($('#credit-tmpl').html()),
    initialize: function(){
        _.bindAll(this, "render");
        this.render();
    },
    render: function(){
        this.$el.html(this.template());
    }
});

ProfileRouter = Backbone.Router.extend({
    initialize : function() {

    },
    routes : {
        '' : 'profile',
        'detailedProfile' : 'detailedProfile',
        'credit' : 'credit'
    },
    profile : function() {
        $('#img-loader').fadeIn();
        currentView = new mainProfileView();
        currentView.render();
    },
    credit : function() {
        $('#img-loader').fadeIn();
        if (currentView){
           currentView.undelegateEvents();
           delete currentView;
        }

        currentView = new creditView();
        currentView.render();
    },
    moreReviews : function() {
        $('#img-loader').fadeIn();
        if (currentView){
           currentView.undelegateEvents();
           delete currentView;
        }

        review = new Reviews;
        review.fetch({
            data: {
                  profile_id : profile_id
            },
            type : 'POST',
            success: function(model,response,options) {
                currentView = new moreReviewView({reviews : model});
                currentView.render();
            },
            error: function(model,response,options) {
                //console.log(response.responseText);
            }

        });
    }
});
我的模板文件的一部分是

<script type="text/template" id="main-profile-tmpl">
.......
            <div class="block with-padding service-area-container">
                <h5>Social</h5>
                <div class="addthis_toolbox addthis_default_style ">
                    <a class="addthis_button_facebook_like" fb:like:layout="button_count"></a>
                    <a class="addthis_button_tweet"></a>
                    <a class="addthis_button_pinterest_pinit"></a>
                    <a class="addthis_counter addthis_pill_style"></a>
                </div>
            </div>
    </script>

.......
社会的

您不仅需要在每次加载模板时调用addthis\u小部件脚本,还需要清除“缓存”变量

    if (window.addthis) {
        window.addthis = null;
        window._adr = null;
        window._atc = null;
        window._atd = null;
        window._ate = null;
        window._atr = null;
        window._atw = null;
        }  
    var uniqueUrl = "http://s7.addthis.com/js/300/addthis_widget.js#pubid=XXX";
    $.getScript(uniqueUrl)
    .done(function(script) {
      addthis.init();
    });

您不仅需要在每次加载模板时调用addthis_小部件脚本,还需要清除“缓存”变量

    if (window.addthis) {
        window.addthis = null;
        window._adr = null;
        window._atc = null;
        window._atd = null;
        window._ate = null;
        window._atr = null;
        window._atw = null;
        }  
    var uniqueUrl = "http://s7.addthis.com/js/300/addthis_widget.js#pubid=XXX";
    $.getScript(uniqueUrl)
    .done(function(script) {
      addthis.init();
    });

你解决了这个问题吗?你解决了这个问题吗?