react-native-calendar icon indicating copy to clipboard operation
react-native-calendar copied to clipboard

Events are not shown when adding events to array dynamically

Open dongawli opened this issue 8 years ago • 1 comments

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.

dongawli avatar May 17 '17 13:05 dongawli

@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.

noitcudni avatar May 21 '17 04:05 noitcudni