javascript - Ember.js loading simple data from API -


so, have simple page ember.js i'm trying load data rest api.

api provided apiary.io , returns following simple data

{"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 model accquires data app.semantic.find() , not put items template.

but works expected, if set array value in 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"}];     } }); 

where problem?

the link api - http://bug0r.apiary.io/api/semantics

the jsfiddle code - jsfiddle

full code here

 var app = window.app = ember.application.create({     version: '1.0',     rootelement: '#approot',     log_transitions: true }); app.deferreadiness(); // not initialize until 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 create ember.route instance 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 initialization 

edit: 1. json api fixed, still not work.

the api returns invalid json (key value should not seperated = : , properties should enclosed in quotes)

{ "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"} ] } 

should

{ "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"} ] } 

Comments