繁体   English   中英

在React中找不到流星方法(404)

[英]Meteor method not found in React (404)

我在尝试将React集成到Meteor时遇到了困难,并且确实发生了一些奇怪的事情。

我有一个要从中调用Meteor方法的组件,我只是先进行一些测试,以查看一切是否都按预期工作(当我使用Blaze时工作了),但是我(除了预期的失败)得到了Method '[meteor method name]' not found在流星方法调用之后, Method '[meteor method name]' not found带有404 Method '[meteor method name]' not found

错误:

---------------prev-inv
meteor.js?hash=27829e9…:932 Exception while simulating the effect of invoking 'cloudinaryImageContents.insert' _class {error: "validation-error", reason: ""name" is required", details: Array(1), message: ""name" is required [validation-error]", errorType: "Meteor.Error"…} Error
    at new _class (http://localhost:3001/packages/mdg_validation-error.js?hash=c824fee078386259563451e9fa961549731965f5:71:89)
    at throwError (http://localhost:3001/packages/jagi_astronomy.js?hash=e399f2032bcf4df1ed57f144d7ebec90df5fdd3f:10660:17)
    at Validator.validate (http://localhost:3001/packages/jagi_astronomy.js?hash=e399f2032bcf4df1ed57f144d7ebec90df5fdd3f:10691:11)
    at Object.Validators.(anonymous function) [as required] (http://localhost:3001/packages/jagi_astronomy.js?hash=e399f2032bcf4df1ed57f144d7ebec90df5fdd3f:10707:19)
    at ScalarField.validate (http://localhost:3001/packages/jagi_astronomy.js?hash=e399f2032bcf4df1ed57f144d7ebec90df5fdd3f:2411:20)
    at ScalarField.validate (http://localhost:3001/packages/jagi_astronomy.js?hash=e399f2032bcf4df1ed57f144d7ebec90df5fdd3f:2807:33)
    at http://localhost:3001/packages/jagi_astronomy.js?hash=e399f2032bcf4df1ed57f144d7ebec90df5fdd3f:11584:13
    at catchValidationError (http://localhost:3001/packages/jagi_astronomy.js?hash=e399f2032bcf4df1ed57f144d7ebec90df5fdd3f:11513:7)
    at http://localhost:3001/packages/jagi_astronomy.js?hash=e399f2032bcf4df1ed57f144d7ebec90df5fdd3f:11582:5
    at arrayEach (http://localhost:3001/packages/jagi_astronomy.js?hash=e399f2032bcf4df1ed57f144d7ebec90df5fdd3f:13376:11)
ImageContentAddPage.jsx:26 ---------------after-inv
ImageContentAddPage.jsx:23 errorClass {error: 404, reason: "Method 'cloudinaryImageContents.insert' not found", details: undefined, message: "Method 'cloudinaryImageContents.insert' not found [404]", errorType: "Meteor.Error"…} undefined
ImageContentAddPage.jsx:24 -----inv

组件:

import React, { Component } from 'react';
import TextField from 'material-ui/TextField';
import RaisedButton from 'material-ui/RaisedButton';

import PageSection from '/imports/ui/components/Misc/PageSection';
import ImageUploaderMiddleware from '/imports/ui/components/Middleware/ImageUploaderMiddleware';
import CreatorMiddleware from '/imports/ui/components/Middleware/CreatorMiddleware';

import '/imports/api/contents/images/CloudinaryImage/methods.js';

export default class ImageContentAddPage extends CreatorMiddleware {
  componentWillMount(){
    this.setState({
      path: '/some/path',
      methodName: 'cloudinaryImageContents.insert',
      data: {}
    });
  }

  handleCreate(){
    console.log('---------------prev-inv');
    Meteor.call( this.state.methodName, this.state.data, function(err, res){
      console.log(err, res);
      console.log('-----inv');
    });
    console.log('---------------after-inv');
  }

  render () {
    return (
      <div>
        <TextField hintText="Image name" floatingLabelText="Name" />
        <TextField hintText="Image description" floatingLabelText="Description" />
        <ImageUploaderMiddleware>
        <RaisedButton label="Upload" primary />
        </ImageUploaderMiddleware>
        <div>
          {this.state.error ? this.state.error.reason : null}
        </div>
        <RaisedButton label="Create" primary onTouchTap={this.handleCreate.bind(this)} />
      </div>
    );
  }
}

流星方法:

Meteor.methods({
  'cloudinaryImageContents.insert'(image){
    image = image || {};
    image.userId = this.userId;
    let newImage = new CloudinaryImageContent(image);
    return newImage.save();
  }
});

如果您将/imports文件夹用于collections API和方法,请确保将方法文件导入服务器入口点/server/main.js ),否则您的方法将在服务器端不可见。

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM