How to use ember data model to fetch data from a json file and display in template


#1

I need help in 1, how ember model is connected with model() hook in router.js 2, how we can save and retrieve data from json file using ember model. 3, where we need to specify the url of json file. 4, do I need to create a JsonAPIAdapter for it using cli.


#2

I guess you would just request the data via ajax (e.g. Ember.$.getJSON('/my-data.json')) and then push it manually into the store: https://guides.emberjs.com/v2.3.0/models/pushing-records-into-the-store/


#3

Or, if you want to use ember data, override the specific urlForXXX method in either the application adapter or a model specific adapter.

http://emberjs.com/api/data/classes/DS.RESTAdapter.html#method_urlForFindAll

For example, if you have a file posts.json in your public directory which you want returned from store.findAll('post'), do this:

// adapters/post.js
export default ApplicationAdapter.extend({
  urlForFindAll(modelName) {
    return 'posts.json';
  }
});

#4

Am getting this error

test-app@model:todo::ember441:1

test-app@model:todo::ember442:2

test-app@model:todo::ember443:3

when i used

urlForFindRecord(todo) { return ‘todos.json’; }


#5

whoops, I copied the wrong one. it should be urlForFindAll. I modified my original response,


#6

I did the same . but data is not showing.


#7

Brother I dont have previous experience in any javascript framework.

How could I learn all the functionalities of ember with a simple backend.

what is adapters used for.

how do i have to configure my ember app with any of database(I mean sample data to work).

I am using ember cli

how can i create a simple form using ember and save form data to my local.


#8

can you post on github?


#9

I dont know how to use github


#10

Can I write actions inside model() hook of router

like

model() {

return $.json();

actions: {

x(): {}, y(): {}

} }