0

So, I have a simple page with Ember.js where i'm trying to load data from rest api.

Api is provided by apiary.io and returns the 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 is model that accquires data by App.Semantic.find() and it does not put items to template.

But it works as expected, if I 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 is the problem?

The link to API - http://bug0r.apiary.io/api/semantics

The jsFiddle with code - jsfiddle

Full code here

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.

1 Answer 1

1

The API returns invalid JSON (key value should not be seperated by = but by : and properties should be 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 be

{ "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"}
] }
Sign up to request clarification or add additional context in comments.

1 Comment

check updated answer. JSON properties need to be enclosed in quotes according to the JSON spec.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.