javascript - How to update data in Meteor and React? -


i started using meteor , react js in work , i'm beginner both of them. building blog , need update posts i'm having problems when updating data, data not saved in collection. have following collection: posts(title,slug,content,author,category , tags[]). fields need update are: title,content,author,category , tags[]. far i've tried solve no positive results. use astronomy schema. hope can give advice. here code:

import ....other imports import { posts } '../../lib/collections.jsx';  class postmanager extends component {  constructor(props) {   super(props);   this.state = {     title: props.post.title,     content: props.post.content,     category: props.post.category,     tags: props.post.tags,     slug: props.post.slug,     author: props.post.author,   };  this.updatepost = this.updatepost.bind(this); }  updatepost(event) {   event.preventdefault();   const post = this.props.post;   const title = this.state.title.defaultvalue;   const slug = this.state.slug.defaultvalue;   const content = this.state.content.defaultvalue;   const category = this.state.category.defaultvalue;   const tags = this.state.tags.defaultvalue;   const author = this.state.author.defaultvalue;    post.set({   title,   content,   category,   tags,   slug,   author, }); if (post.validate(false)) {   const id = post.save();   console.log(id); } console.log(post.getvalidationerrors(false)); } render() {  return (   <div>     <h1>manager post view</h1>     <form       classname="new-resolution"       onsubmit={this.updatepost}     >       <p>title:</p>       <input type="text" ref="title"         defaultvalue={this.state.title}              />       <p>text:</p>       <input type="text" ref="content"           defaultvalue={this.state.content} />       <p>category:</p>       <input type="text" ref="category"            defaultvalue={this.state.category} />       <p>author:</p>       <input type="text" ref="author"           defaultvalue={this.state.author} />       <p>tags:</p>       <input type="text" ref="tags" defaultvalue={this.state.tags} />       <button>update post</button>     </form>   </div>   );  } } postmanager.proptypes = {  ready: proptypes.bool.isrequired, };  export default createcontainer(() => { const slug = flowrouter.getparam('slug'); const handle = meteor.subscribe('posts'); return {   ready: handle.ready(),   post: posts.find({ slug }).fetch()[0],   };  }, postmanager); 

some of errors are: property map undefind , invariant violation, attempt update postmanager.

i able make work , update data, correct answer:

class postmanager extends component {  constructor(props) {   super(props);   console.log(props);    this.state = {      title: props.post.title,      content: props.post.content,      category: props.post.category,      tags: props.post.tags,      slug: props.post.slug,      author: props.post.author,    };    this.updatepost = this.updatepost.bind(this);  }  updatepost(event) {   event.preventdefault();   const post = this.props.post;   const title = this.refs.title.value.trim();   const slug = this.state.slug;   const content = this.refs.content.value.trim();   const category = this.refs.category.value.trim();   const tags = this.state.tags;   const author = this.refs.author.value.trim();    post.set({     title,     content,     category,     tags,     slug,     author,   });    if (post.validate(false)) {     const id = post.save();     console.log(id);   }   console.log(post.getvalidationerrors(false));  }   handlecheckboxlistupdate(tags) {   this.state.tags = tags;   this.setstate(this.state);  }   render() {    return (      <div>        <h1>manager post view</h1>        <form         classname="new-resolution"         onsubmit={this.updatepost}        >         <p>title:</p>         <input            ref="title"            type="text"            defaultvalue={this.state.title}          />         <p>text:</p>         <input            ref="content"            type="text"            defaultvalue={this.state.content}          />         <p>category:</p>         <input            type="text"            ref="category"            defaultvalue={this.state.category}          />         <p>author:</p>         <input            ref="author"            type="text"            defaultvalue={this.state.author}          />         <p>tags:</p>         <input            type="text"            ref="tags"            defaultvalue={this.state.tags}          />         <button>update post</button>       </form>     </div>     );    }   } } 

Comments

Popular posts from this blog

gridview - Yii2 DataPorivider $totalSum for a column -

java - Suppress Jboss version details from HTTP error response -

Sass watch command compiles .scss files before full sftp upload -