0
Mongo-Collection
にデータを挿入するにはcomponent
という形式を使用しています。私が保存されている情報のためterminal
をチェックインすると、私はsuccessfuly Select
入力からTitle
やデータを保存するが、both
URLとfile
入力のnull
の値を持っています。ここでメロノーはmongodbストア 'null'にURLを挿入します
Meteor.methods({
'posts.insert' : function(post) {
return Posts.insert({
createdAt: new Date(),
title: post.title,
social: post.social,
link: this.link,
file: this.file
});
}
});
は、フォーム送信処理するためのコンポーネントのコードです:ここで
は輸入フォルダにinsertメソッドを処理するためのコードである
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;
PS:それはこれらのトピックのうちですいくつかの外部リソースを指摘したり、ローカルマシンから新しいイメージ(パブリックフォルダから静的ではない)をアップロード/保存してフロントエンドビューに提供できるかどうかを説明することができれば、感謝します。
ハーフィズありがとう、あなたは道に私を持ち帰った:) – volna