Facebook Like Box未加载到Ember应用程序 [英] Facebook Like Box not loading on Ember app

查看:139
本文介绍了Facebook Like Box未加载到Ember应用程序的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试让这个盒子在我们的ember应用程序中工作,在一个名为的模板中,关于。问题是,如果我从另一个路由(而不是关于路由)输入ember应用程序,则导航到关于路由与链接到帮助者,则不会呈现类似的框。相反,如果我直接输入/刷新关于路由,它呈现很好。任何关于如何使其渲染的想法即使有人从另一条路线导航到该路线?

I'm trying to get the like box to work inside our ember app, in a template called about. The problem is that if I enter the ember app from another route (instead of about route), then navigate to the about route with link-to helpers, then the like box is not rendered. Instead, if I enter/refresh the about route directly, it renders just fine. Any ideas on how to make it render even if somebody navigates to that route from another route ?

templates / about.hbs:

...
<div class = "fb-like-box" data-href = "https://www.facebook.com/app-link" data-width = "250"
                 data-height = "313" data-colorscheme = "light" data-show-faces = "true" data-header = "false"
                 data-stream = "false" data-show-border = "true"></div>
...

views / application.js: / p>

views/application.js:

export default Ember.View.extend({

  facebook_app_id: config.APP.facebook_app_id,

  initLibs: function ()
            {
              // initialize Facebook SDK
              var facebook_id = this.facebook_app_id;
              window.fbAsyncInit = function ()
              {
                FB.init({
                  appId:   facebook_id,
                  xfbml:   true,
                  version: 'v2.1'
                });
              };
              (function (d, s, id)
              {
                var js, fjs = d.getElementsByTagName(s)[0];
                if (d.getElementById(id))
                {
                  return;
                }
                js = d.createElement(s);
                js.id = id;
                js.src = "//connect.facebook.net/en_US/sdk.js";
                fjs.parentNode.insertBefore(js, fjs);
              }(document, 'script', 'facebook-jssdk'));
            }.on('didInsertElement')
});


推荐答案

默认情况下,Facebook JS SDK通过初始化一次文档,并查找要解析并转换为FB社交插件的元素。但是,如果您稍后加载并添加这些元素,那当然不起作用。

By default the Facebook JS SDK "goes through" your document once when it is initialized, and looks for elements to parse and convert into FB social plugins. But if you only load and add those elements later, that of course doesn’t work.

但是,SDk提供了一种重新解析文档的方法, FB.XFBML.parse - 所以在你的新的元素被添加到DOM。 (您可以让它再次查看整个文档,也可以传入对特定DOM元素的引用,以便它只评估文档的子树,以获得更好的性能。)

But the SDk offers a method to re-parse the document for such elements, FB.XFBML.parse – so call that after your new elements are added to the DOM. (You can either let it look through the whole document again, or pass in a reference to a specific DOM element, so that it will only evaluate a "sub-tree" of the document, for better performance.)

这篇关于Facebook Like Box未加载到Ember应用程序的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆