如何在 Meteor + React 中使用 chimpmail?

How to use chimpmail in Meteor + React?

首先感谢您花时间阅读本文,我不得不说我是网络开发领域的新手。我一直要求在项目中实施 mailchimp(我从未听说过),为此我刚开始搜索有关 chimpmail API also I followed the tutorial from meteorchef 的信息,问题是我可以完成这项工作,我发现很难用 React 实现这个。当我输入邮件和 运行 onSubmit 方法时,我的方法出现问题,控制台输出显示 "method handleSubscriber not found"。到目前为止,我只是制作了教程中的 handleSubscriber 部分,我没有显示任何电子邮件列表 jet。我正在 运行 使用 meteor --settings=settings.json 安装我的 Meteor 应用程序。非常感谢您的帮助。

更新

我收到了一条有用的评论,指出我应该将我的方法文件添加到我的服务器目录中。通过这样做,我不再得到 "method handleSubscriber not found" 而不是我现在得到的 Exception while invoking method 'handleSubscriber' Error: Match error: Expected object, got null

这是我的 Meteor 包:

meteor-base
mobile-experience
mongo
blaze-html-templates
reactive-var
jquery
tracker
library

standard-minifier-css
standard-minifier-js    
es5-shim
ecmascript

react-meteor-data@0.2.6-beta.16
accounts-ui
accounts-password
practicalmeteor:mocha
miro:mailchimp
fortawesome:fontawesome
themeteorchef:bert
standard-app-packages
underscore
themeteorchef:jquery-validation
check

这是我的settings.json

{
  "public": {},
  "private": {
     "MailChimp": {
       "apiKey": "theapikey",
       "listId": "thislsitId"
      }
   }
}

chimpMail.js

import { Meteor } from 'meteor/meteor';
import { check } from 'meteor/check';

const settings = Meteor.settings.private.MailChimp;
const chimp = new MailChimp( settings.apiKey, { version: '2.0' });
const listId = settings.listId;

Meteor.methods({
  'handleSubscriber'(subscriber) {
    check(subscriber, {
      email: String,
      action: String,
    });
  try {
    const subscribe = chimp.call('lists', subscriber.action, {
      id: listId,
       email: {
        email: subscriber.email,
       },
    });
     return subscribe;
    } catch (exception) {
      return exception;
   }
 },
});

这是我的emailSubscription.jsx

import { Meteor } from 'meteor/meteor';
import React, { Component } from 'react';
import { createContainer } from 'meteor/react-meteor-data';

class EmailSubscription extends Component {
   handleOnSubmit(event) {
     event.preventDefault();

     Meteor.call('handleSubscriber', this.props.subscriber,        
       function(error, response) {
       if (error) {
          Bert.alert(error.reason, "warning");
       } else {
       if (response.complete || response.euid) {
          const subscribeMessage = 'Please confirm your email to  
           complete your subscription!';
          const unsubscribeMessage = subscriber.email + 'successfully 
           unsubscribed!';
          const message = subscriber.action === "subscribe" ? 
           subscribeMessage : unsubscribeMessage;

          Bert.alert(message, "success");
       } else {
         Bert.alert(response.message, "warning");
       }
     }
   });
}

render() {
  return (
    <div className="container">
      <form onSubmit={this.handleOnSubmit.bind(this)} 
         className="emal-submit"
       >
        <input type="email" placeholder="email@example.com" />
        <button>Sign Me Up!</button>
      </form>
    </div>
   );
  }
}
export default createContainer(() => {
}, EmailSubscription);

"method handlerSubscriber not found" is say that your method.

请导入服务器目录中的方法文件。

Exception while invoking method 'handleSubscriber' Error: Match error: Expected object, got null

这是您收到的异常,因为订阅者需要是一个对象,但您从客户端发送 null。检查抛出此异常的函数。