Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Events are not shown when adding events to array dynamically #137

Open
dongawli opened this issue May 17, 2017 · 1 comment
Open

Events are not shown when adding events to array dynamically #137

dongawli opened this issue May 17, 2017 · 1 comment

Comments

@dongawli
Copy link

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.

@noitcudni
Copy link
Contributor

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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants