Ember pagination full example

The updated example below works with ember.js RC1 — 03/14/2013 First you need to add a pagination like mixin as one doesn’t yet exist in the ember core var get = Ember.get, set = Ember.set; Ember.PaginationMixin = Ember.Mixin.create({ pages: function() { var availablePages = this.get(‘availablePages’), pages = [], page; for (i = 0; i < … Read more

Handling errors with the (now default) Ember Data JSON-API adapter

Note the answer below is based on the following versions: DEBUG: ——————————- ember.debug.js:5442DEBUG: Ember : 1.13.8 ember.debug.js:5442DEBUG: Ember Data : 1.13.9 ember.debug.js:5442DEBUG: jQuery : 1.11.3 DEBUG: ——————————- The error handling documentation is unfortunately scattered around at the moment as the way you handle errors for the different adapters (Active, REST, JSON) are all a bit … Read more

Get current route name in Ember

This worked for me on 1.3.0-beta (and a quick glance at the source for 1.1.2 suggests it would work there too): App.__container__.lookup(‘router:main’).location.lastSetURL Note that the documentation states: At present, it relies on a hashchange event existing in the browser. However, I believe it’s strongly suggested that App.__container__ not be used in production code. A more … Read more

Using Ember.js, how do I run some JS after a view is rendered?

You need to override didInsertElement as it’s “Called when the element of the view has been inserted into the DOM. Override this function to do any set up that requires an element in the document body.” Inside the didInsertElement callback, you can use this.$() to get a jQuery object for the view’s element. Reference: https://github.com/emberjs/ember.js/blob/master/packages/ember-views/lib/views/view.js

Ember component send action to route

For short answer you can you can use ember-route-action-helper addon. <button {{action (route-action ‘onButtonClick’)}}>ClickToCallRouteAction</button> There are three way of actions communication, 1. Old style classic functions style ie., passing function name as string from top to bottom. and in all the places we need to define same function and provide. Use sendAction to bubble. and … Read more

Ember-data embedded records current state?

Using the ActiveModelSerializer you can include the EmbeddedRecordsMixin which allows you to use embedded records. (In the canary versions, 1.0 beta 9+, you can use the JsonSerializer/RESTSerializer as well) Serializer App.ColorSerializer = DS.ActiveModelSerializer.extend(DS.EmbeddedRecordsMixin, { attrs: { foos: {embedded: ‘always’} } }); Models App.Color = DS.Model.extend({ color: DS.attr(), foos: DS.hasMany(‘foo’) }); App.Foo = DS.Model.extend({ name: DS.attr() … Read more