I am facing an issue with my Ember.js page where I am trying to retrieve data from a REST API.
The API is provided by apiary.io and it returns a simple set of data as shown below:
{"semantics": [
{key : "11111", name : "Block 1"},
{key : "22222", name : "Block 2"},
{key : "33333", name : "Block 3"},
{key : "44444", name : "Block 4"},
{key : "55555", name : "Block 5"}
]}
The problem lies in the model which is supposed to fetch data using App.Semantic.find() but it is not displaying the items in the template.
However, the model works fine if I manually set the array values in the route.
App.SemanticRoute = Ember.Route.extend({
model: function () {
//return App.Semantic.find();
return [{key:111,name:"aaaa"},{key:222,name:"qqqqq"},
{key:3333,name:"bbbb"},key:555,name:"ccc"}];
}
});
What could be causing this issue?
Here is the link to the API -
Check out the jsFiddle with the code - jsfiddle
For the full code, refer to the snippet below:
var App = window.App = Ember.Application.create({
VERSION: '1.0',
rootElement: '#appRoot',
LOG_TRANSITIONS: true
});
App.deferReadiness(); // do not initialize it until we are ready
App.Adapter = DS.RESTAdapter.extend({
namespace: 'api',
url: 'http://bug0r.apiary.io'
});
App.Adapter.map('Semantic', {
primaryKey: 'key'
});
App.Store = DS.Store.extend({
revision: 12,
adapter: App.Adapter
});
App.Router.map(function () {
// each call will create Ember.Route instance for customizing route
this.resource("semantic", {
path: "/"
});
this.route("about", {
path: "/about"
});
});
/* Symantic model*/
App.Semantic = DS.Model.extend({
key: DS.attr('string'),
name: DS.attr('string'),
});
App.SemanticRoute = Ember.Route.extend({
model: function () {
return App.Semantic.find();
}
});
App.advanceReadiness(); // ready for initialization
Edit: 1. JSON api fixed, but still not work.