Asked By: Anonymous
I’m new to web development stuff and have been looking at some ember, I wanted to try running this with Spring boot. I got spring boot working and was able to run the sample blog example created with ember.
Now I want to some data read from the spring server, for example I can go to http://localhost:8080/greeting?name=User and get the following displayed onto the page
{“id”:12,”content”:”Hello, User!”}
What I want to do is get ember to read make that call instead of me manually adding it in the url and getting ember to then display that data.
So in ember my app.js looks like this
App.IndexRoute = Ember.Route.extend({
model: function() {
return $.getJSON("http://localhost:8080/greeting?name=User");
}
});
This I believe makes the call. I was trying to re-display the data onto the onto the index.html like this:
<script type="text/x-handlebars" data-template-name="index">
<Not sure what to put here>
</script>
I may be missing something obvious or not getting something. I apologize if thats the case. Any help will be welcome
Solution
Answered By: Anonymous
The model hook in your route should resolve to {"id":12,"content":"Hello, User!"}
. Once that is resolved, Ember will populate the model
property of the corresponding controller (in this case, IndexController
, which is auto-generated if you don’t provide one).
As the index template you are using is backed by that controller, you can refer to any of its properties, including model
:
<script type="text/x-handlebars" data-template-name="index">
{{model.content}}
</script>
I hope you can make it work!