Positional index in Ember.js collections iteration

It’s old question but still gets a lot of hits. In the current version of Ember.JS one can use _view.contentIndex to display current index inside the loop. {{#each}} Index: {{_view.contentIndex}} {{/each}} If you need an adjusted index (for instance starting from 1) then there is a possibility of creating reusable helper increment Ember.Handlebars.registerBoundHelper(‘increment’, function(integer) { … Read more

Difference between Ember.get() and this.get()

Welcome to Ember 😉 Every object that extends Ember Observable mixin supports the get() method (among others). When you call this.get(), the this must refer to such an object (Route, Controller, Component, your own class that extends Ember.Object and so on). Calling get() on plain object would cause a failure. Let me show the difference: … Read more

What is the purpose of the Ember.Container

The goal of the container is to provide a more general-purpose mechanism for describing module dependencies than the ad-hoc approach we had been using. For example, imagine you want to find the controller for the post route. The default Ember rules are that we would look it up as App.PostController. Before the container, we would … Read more

Is it possible to load a Handlebars template via Ajax?

You can register new templates in Ember.TEMPLATES. They will then be available to views. An excerpt from my code (jQuery Ajax handler): success: function(data) { $(data).filter(‘script[type=”text/x-handlebars”]’).each(function() { templateName = $(this).attr(‘data-template-name’); Ember.TEMPLATES[templateName] = Ember.Handlebars.compile($(this).html()); }); } That’s it.

Client-side Javascript app – url routing with no hash tag

In Ember.js (version 1.0.0rc3) this can be accomplished by using the Ember.js location API: App.Router.reopen({ location: ‘history’ }); And then setting the web server to redirect traffic to the Ember application. To give a concrete example here is a basic Apache .htaccess file redirecting traffic to the Ember application located in index.html: RewriteEngine on RewriteCond … Read more