首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >流星反应-将url插入mongodb存储区'null‘

流星反应-将url插入mongodb存储区'null‘
EN

Stack Overflow用户
提问于 2016-07-25 22:36:45
回答 1查看 64关注 0票数 0

我使用表单component将数据插入到Mongo-Collection中。当我签入terminal以获取存储的信息时,我确实成功地存储了来自Select输入的Title和数据,但是对于both url和file输入有null的值。

下面是在导入文件夹中处理insert方法的代码:

代码语言:javascript
复制
Meteor.methods({

 'posts.insert' : function(post) {

    return Posts.insert({
      createdAt: new Date(),
      title: post.title,
      social: post.social,
      link: this.link,
      file: this.file
    });
  }
});

以下是处理表单提交的组件代码:

代码语言:javascript
复制
import React, { Component } from 'react';

class AddPost extends Component {

  constructor(props) {
    super(props);

    this.state = {error: ''};
  }

  handleSubmit(event) {
    event.preventDefault();

    const title = this.refs.title.value;
    const social = this.refs.social.value;
    const link = this.refs.link.value;
    const file = this.refs.file.value;

    Meteor.call('posts.insert', {title, social, link, file});
  }

  render() {
    return (
        <div className="modal fade" id="myModal" tabIndex="-1" role="dialog" aria-labelledby="myModalLabel" aria-hidden="true">
          <div className="form-outer">
            <form id='add_post' onSubmit={this.handleSubmit.bind(this)}>
                <div className='form-text form-header'>
                  <p><strong>Hey</strong>, master<span className='error'>{this.state.error}</span></p>
                  <p>Lets share something new today?</p>
                </div>
                <input ref="title" type="text" className="form-input" placeholder="What about the title?" />
                <div className='form-text form-header form-header-distance'>
                  <p>Where should I point the way?</p>
                </div>
                <select ref="social" className="form-select">
                  <option>Select</option>
                  <option>Instagram</option>
                  <option>Twitter</option>
                </select>
                <input ref="link" type="url" className="form-input" placeholder="Point the way" />
                <div className='form-text form-header form-header-distance'>
                  <p>And what about the image?</p>
                </div>
                <label className="file form-file">
                  <input ref='file' className='form-input' type="file" id="file" />
                  <span className="file-custom"></span>
                </label>
                <button type="button" className="form-button" data-dismiss="modal">Close</button>
                <button type="sumbit" className="form-button" >Save</button>
            </form>
          </div>
        </div>
    );
  }
}

export default AddPost;

答:这不是这些问题的主题,但如果你能告诉我一些外部资源,或者解释一下是否可以从本地机器上传/存储新图像(不是静态的),并将它们提供给前端视图,我会非常感激。

EN

回答 1

Stack Overflow用户

回答已采纳

发布于 2016-07-25 23:03:06

让你的流星方法如下:

代码语言:javascript
复制
Meteor.methods({
  'posts.insert'(post){
    post.createdAt: new Date();
    Posts.insert(post);
  }
})
票数 1
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/38578442

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档