Skip to content

Instantly share code, notes, and snippets.

@sheriffderek
Last active December 25, 2016 19:56
Show Gist options
  • Save sheriffderek/fd4ba41e49f5980c5d3eeae95dce357f to your computer and use it in GitHub Desktop.
Save sheriffderek/fd4ba41e49f5980c5d3eeae95dce357f to your computer and use it in GitHub Desktop.
Ajax example
import Ember from 'ember';
export default Ember.Controller.extend({
appName: 'Ajax example'
});
import Ember from 'ember';
export default Ember.Route.extend({
model: function() {
const apiUrl = 'https://jsonplaceholder.typicode.com/posts';
return $.getJSON( apiUrl ).then( function(json) {
// return json; // return everything or...
return json.map( function(post) { // map the data and transform the payload to something you would rather work with
return {
number: post.id, // example to change the payload
title: post.title
};
});
});
}
});
<h1>{{appName}}</h1>
<ul class='post-list'>
{{#each model as |post|}}
<li class='post'>
{{post.number}}:
{{post.title}}
</li>
{{/each}}
</ul>
{
"version": "0.10.7",
"EmberENV": {
"FEATURES": {}
},
"options": {
"use_pods": false,
"enable-testing": false
},
"dependencies": {
"jquery": "https://cdnjs.cloudflare.com/ajax/libs/jquery/1.11.3/jquery.js",
"ember": "2.10.0",
"ember-data": "2.10.0",
"ember-template-compiler": "2.10.0",
"ember-testing": "2.10.0"
},
"addons": {}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment