Help with Ember model DS and Json

Hey I am kind a newbie to ember and I am looking for a help: Here is my json file:

{ “id”: 1, “title”: “Grand Old Mansion”, “owner”: “Veruca Salt”, “city”: “San Francisco”, “type”: “Estate”, “bedrooms”: 15, “image”: “https://upload.wikimedia.org/wikipedia/commons/c/cb/Crane_estate_(5).jpg” }

my model:rental.js import DS from ‘ember-data’;

export default DS.Model.extend({ title: DS.attr(), owner: DS.attr(), city: DS.attr(), type: DS.attr(), image: DS.attr(), bedrooms: DS.attr() });

and my index.hbs:

{{#each model as |rental|}}

{{rental.title}}

Owner: {{rental.owner}}

Type: {{rental.type}}

Location: {{rental.city}}

Number of bedrooms: {{rental.bedrooms}}

{{/each}}

and my index.js route:

import Ember from ‘ember’;

export default Ember.Route.extend({ model() {

}, });

Now i have been surfing around internet to explain me how can I connect my json file so my ember app can detect data from it and index.js model can route to index.hbs

You need to fill in your model hook with either a jQuery AJAX call to your JSON file or using the store, like this.store.findAll('rental'). If you are using a static JSON file, you will have to create an adapter that looks for JSON files.

The hook @skaterdav85 is talking about is in the route. Just check ember guide on routing and model. It should gdt you started

Do you know any tutorial out there that can help me understand adaptors. I find Ember.js documentation not that helpful and alot of tutorials are either older version or dont talk about adaptors in ember 2.0

Here is an article I wrote that is up to date: Fit Any Backend Into Ember with Custom Adapters & Serializers - Ember Igniter

And @skaterdav85 gave a great presentation about this topic: 404 Not Found

2 Likes