Open dongawli opened 7 years ago
@dongawli A string representation of a data structure is different from an actual data structure. If you really want and need your first approach to work, you might try calling eval on the expression.
Then again, why would you want to do that? Maybe you have a good reason. Instead, you might want to construct the data structure (an array of associative arrays) dynamically.
Hi,
I am adding events dynamically to the calendar using string .
Here is the code for same ( this code is not working) var eventstr = "{date: '"+ this.state.SelectedDate + "', hasEventCircle: {backgroundColor: '" + event1color +"'}}"; var event1 = [{eventstr}]; let updatedArray = this.state.eventItems.concat(event1); this.setState({eventItems:updatedArray});
Whereas, if I declared event array like this then its showing properly.
var event1 = [{date: '2017-05-19', hasEventCircle: {backgroundColor: '#ccedcc'}}]; let updatedArray = this.state.eventItems.concat(event1); this.setState({eventItems:updatedArray});
Can you please help me what is wrong with 1st approach ? How to construct the event string and add to the events array?
Thank you.