Ember WordPress test 1

jetpackAfter installing WordPress Jetpack on the broerse.net WordPress site and some config work it is possible access this json data:

http://public-api.wordpress.com/rest/v1/sites/58826716/posts/?number=4

To create an Ember site like https://broerse.net/ember/wp1/ download the Ember Starter kit from http://emberjs.com/ and replace app.js and index.html with these files:

index.html


<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<title>Ember Starter Kit</title>
  <link rel="stylesheet" href="css/normalize.css">
  <link rel="stylesheet" href="css/style.css">
</head>
<body>
  <script type="text/x-handlebars">
    <h2>Welcome to Ember.js</h2>

    {{outlet}}
  </script>

  <script type="text/x-handlebars" id="index">
    <ul>
      {{#each}}
      <li> {{title}} </li>
      {{/each}}
    </ul>
  </script>

  <script src="js/libs/jquery-1.10.2.js"></script>
  <script src="js/libs/handlebars-1.1.2.js"></script>
  <script src="js/libs/ember-1.2.0.js"></script>
  <script src="js/app.js"></script>
</body>
</html>

app.js



App = Ember.Application.create();

App.IndexRoute = Ember.Route.extend({
  model: function() {
    return Ember.$.ajax({ url: 'https://public-api.wordpress.com/rest/v1/sites/58826716/posts/?number=4', dataType: "jsonp", type: 'GET' }).then(function(data) {
      return data.posts;
    });
  }
});

That’s all there is to it. Happy Embering!


Comments

Comments are closed.