Reputation: 1557
I'm building a web app with Spark Java, OrientDB, and hopefully React.
With Spark Java and Velocity templates, I can access the server side data in the template and do my rendering logic based off of that. Since React is client side, how do I include that same data-model with the response so that I don't have to go back to the server with AJAX?
If I convert my POJO/Map/List to JSON, how can I include that data with the initial HTML/React without going back to the server to fetch it?
Upvotes: 1
Views: 610
Reputation: 669
You should output an html script tag containing a javascript variable with your JSON serialized data.
Something like this:
<script>
window.myData = $myData;
</script>
Then you can access these data client side.
Upvotes: 1