Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    text
    copied!<p>Without ember-data you would typically put direct getJSON with jQuery inside the <code>model</code> method on the route. The <code>model</code> methods supports promises so you can reuse the jQuery promise.</p> <p>For instance given the route to load a list of images for the <code>/images/tag</code> route using the Flickr api would be,</p> <pre><code>App.Router.map(function() { this.resource('images', { path: '/images/:tag'}); }); App.ImagesRoute = Ember.Route.extend({ model: function(params) { flickerAPI = 'http://api.flickr.com/services/feeds/photos_public.gne?jsoncallback=?'; console.log('ImagesRoute.model', params); return jQuery.getJSON( flickerAPI, { tags: params.tag, tagmode: 'any', format: "json" }) .then(function(data) { console.log('loaded images', data); return data; }) .then(null, function() { console.log('failed to load images'); }); } }); </code></pre> <p>The corresponding controller can access/bind to the properties of the returned json automatically. Or you can alias a few computed properties.</p> <pre><code>App.ImagesController = Ember.ObjectController.extend({ images: function() { return this.get('model').items; }.property('controller'), title: function() { return this.get('model').title; }.property('images') }); </code></pre> <p>And then render it via handlebars using these properties.</p> <pre><code>&lt;script type='text/x-handlebars' data-template-name='images'&gt; &lt;h1&gt;{{title}}&lt;/h1&gt; {{#each image in images}} &lt;img {{bindAttr src='image.media.m'}} /&gt; {{/each}} &lt;/script&gt; </code></pre> <p>Here's a <a href="http://jsbin.com/ofodid/1#/images/alps" rel="nofollow">jsbin example</a> that does this.</p>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload