【问题标题】:Discover Meteor Microscope Share It Button发现流星显微镜分享按钮
【发布时间】:2015-07-26 10:38:30
【问题描述】:

如何在“讨论”按钮的左侧添加“分享”按钮。我希望按钮的样式/颜色与当前的“讨论”按钮相同。

我从https://atmospherejs.com/joshowens/shareit添加了包

我将 {{>shareit}} 添加到 post_item.html 中。

<template name="postItem">
  <div class="post">
    <a href="#" class="upvote btn btn-default {{upvotedClass}}">$</a>
    <div class="post-content">
      <h3>{{title}}</h3>
      <p>
        {{pluralize votes "Vote"}},
        by {{author}},
        <a href="{{pathFor 'postPage'}}">{{pluralize commentsCount "comment"}}</a>
        {{#if ownPost}}<a href="{{pathFor 'postEdit'}}">Edit</a>{{/if}}
      </p>
    </div>
    <a href="{{pathFor 'postPage'}}" class="discuss btn btn-default">Reply</a>
  </div>
</template>

这是假设配置它。我是否将其放在 post.item.html 中?如果是这样,怎么做?我只想要推特按钮。

ShareIt.configure({
useFB: true,          // boolean (default: true)
                      // Whether to show the Facebook button
useTwitter: true,     // boolean (default: true)
                      // Whether to show the Twitter button
useGoogle: true,      // boolean (default: true)
                      // Whether to show the Google+ button
classes: "large btn", // string (default: 'large btn')
                      // The classes that will be placed on the sharing buttons, bootstrap by default.
iconOnly: false,      // boolean (default: false)
                      // Don't put text on the sharing buttons
applyColors: true     // boolean (default: true)
                      // apply classes to inherit each social networks background color
});

这是否在 post_item.js 中启用任何图像卡?我无法弄清楚如何在没有错误的情况下将其放入。

Template.article.helpers({
  shareData: function() {
    return {
      title: this.data,
      author: Meteor.users.findOne(this.authorId)
  }
});

这里是 post_item.js 文件。

Template.postItem.helpers({
  ownPost: function() {
    return this.userId == Meteor.userId();
  },
  upvotedClass: function() {
    var userId = Meteor.userId();
    if (userId && !_.include(this.upvoters, userId)) {
      return 'btn-primary upvotable';
    } else {
      return 'disabled';
    }
  }
});
Template.postItem.events({
  'click .upvotable': function(e) {
    e.preventDefault();
    Meteor.call('upvote', this._id);
  }
});

【问题讨论】:

    标签: javascript html meteor package atmosphere.js


    【解决方案1】:

    所以你有一个模板:

    <template name="postItem">
        ...
        {{>shareIt shareData}}
    </template>
    

    这意味着您还有一个模板对象可以在某处匹配它:

    Template.postItem
    

    这可能包含在以下内容中:

    if (Meteor.isClient) {
        Template.postItem.helpers({
            // your helper can hang out here:
            shareData: function() {
                return {
                  title: this.data,
                  author: Meteor.users.findOne(this.authorId)
                };
            };
        });
        // You can also put your ShareIt.configure here:
        ShareIt.configure({
            useFB: false,
            useTwitter: true,
            useGoogle: false,
            classes: "large btn",
            iconOnly: true,
            applyColors: true
        });
    };
    

    上面也只会显示推特图标。

    现在将其放入哪些文件取决于您的应用程序结构。如果您有一个 post_item.js 并且它正在发送到客户端(例如,它位于项目的客户端文件夹中,或者它不在项目的其他特殊用途文件夹中,如下所述:http://docs.meteor.com/#/full/structuringyourapp ) 那么上面的内容应该适合你。如果您遇到错误,请随时将它们添加到问题中,以便我们提供帮助!

    【讨论】:

    • 是的,我仍然收到错误消息。我添加了 post_submit.js 文件。 @蒂姆
    • 好吧,我不知道 post_submit 是干什么用的。你遇到了什么错误?
    • 糟糕,我放错了。我放了 post_item.js。见上文。我收到“意外的令牌错误”。在构建应用程序时:client/templates/posts/post_item.js:29:10: Unexpected token ;您的应用程序有错误。等待文件更改。 @蒂姆
    • 嗯,这表明您在该文件的第 29 行有语法错误。但是,您发布的部分只有大约 19 行,因此很难调试。我会在 29 之前的某个地方寻找缺少的“;”
    • 这是一个额外的“;”在第 29 行,修复了该部分。现在帖子并没有全部显示出来。顶部的标题字段按钮在那里,但没有帖子。另外,我收到一个黄色连字符错误,上面写着“尚未创建“fb-root”div,自动创建”。此错误在控制台中。这会影响帖子的吗? @蒂姆
    猜你喜欢
    • 1970-01-01
    • 2014-12-31
    • 2014-07-15
    • 1970-01-01
    • 2013-10-26
    • 1970-01-01
    • 1970-01-01
    • 2013-06-02
    • 2012-05-10
    相关资源
    最近更新 更多