Hello everyone,
This is how user schema looks like :-
{
"_id" : "wjYhxgHiwjmRFrD8D",
"profile" : {
"vehicles" : [
{
"vehicleName" : "Audi"
},
{
"vehicleName" : "BMW"
},
{
"vehicleName" : "Hundai i10"
},
{
"vehicleName" : "Duster"
},
{
"vehicleName" : "Duster"
},
{
"vehicleName" : "hehfhf"
},
{
"vehicleName" : "ndffd"
}
]
},
}
I want to show vehicles array using map and also wants to edit it later. Now working on iterating through array only.
import React, { Component } from 'react';
import {createContainer} from 'meteor/react-meteor-data';
import { render } from 'react-dom';
import {PropTypes} from 'prop-types';
import TrackerReact from 'meteor/ultimatejs:tracker-react';
class EditMyProfile extends TrackerReact(Component){
componentWillReceiveProps(nextProps) {
this.setState({
vehicles : nextProps.post.profile.vehicles,
})
this.handleChange = this.handleChange.bind(this);
this.handleSubmit = this.handleSubmit.bind(this);
}
handleChange(event){
const target = event.target;
const name = target.name;
this.setState({
[name]: event.target.value,
});
}
vehiclesList(){
var x = this.state.vehicles;
return x;
}
render() {
if(this.props.post) {
return (
<div className=" col-lg-6 col-lg-offset-3 col-sm-12 col-xs-12 col-md-12">
{this.vehiclesList().map(function(y, i){
return (<li key={i}>{i}</li>);
})
}
</div>
);
}
}
}
EditMyProfileContainer = createContainer((props)=>{
const postHandle = Meteor.subscribe('currentUserfunction');
const post = Meteor.users.findOne({'_id':Meteor.userId()})||{};
const loading = !postHandle.ready();
return {
loading,
post,
};
}, EditMyProfile);
export default EditMyProfileContainer;