How to get JSON data into ember / handlebars template?
I'm new with ember... all stuff related to JSON I can find is using
ember-data, which I am not going to be using (we have an xml not REST
api).
All I am trying to do at the moment is load my sideNav.json data into my
application template.
sideNav.json:
[
{
"label": "Overview",
"pageClass": "nav-home",
"iconClass": "icon-overview",
"link": "index.html"
}, {
"label": "Total Energy",
"pageClass": "nav-totalEnergy",
"iconClass": "icon-meter",
"link": "totalEnergy.html"
}
]
template:
<script type="text/x-handlebars" data-template-name="application">
<div id="sideNav">
<ul>
<li >
<a >
<i ></i><p>{{label}}</p>
</a>
</li>
{{/each}}
</ul>
</div>
</script>
At the moment, I am making this work like so:
App.ApplicationRoute = Ember.Route.extend({
model: function() {
var people = [
{
label: "Overview",
pageClass: "nav-home",
iconClass: "icon-overview",
link: "index.html"
},
{
label: "Total Energy",
pageClass: "nav-totalEnergy",
iconClass: "icon-meter",
link: "totalEnergy.html"
}
];
return people;
}
});
But I would like to keep this data in the separate JSON file, I was
thinking about just using $.ajax() to get the data, but i don't think that
is the best approach.
Thanks
No comments:
Post a Comment