Shany Shany - 1 year ago 33
Javascript Question

Empty array model used in dynamic route

When transitioning to a dynamic route with an empty array as the model, it seems like Ember relates to it as


Thus, if this is the template:

{{#linkTo dynamic arrayProxy}}link{{/linkTo}}

and this is the route definition:

DynamicRoute = Ember.Route.create(function() {
model: function(params) {
return this.modelFor("parent").find(;

serialize: function(model) {
return { name: model.get("name") };

is either
Ember.ArrayProxy.create(content: [])
after clicking on the link:

the model hook will not get called, of course.

The serialize hook will get
as the
, no matter that ArrayProxy is a valid Ember object with its own properties.

Does anyone know how to force ember handle empty arrays differently from

Answer Source

It was my mistake...
Apparently, the link was nested in the template under the following if block:

{{#if arrayProxy}}
  {{#linkTo dynamic arrayProxy}}link{{/linkTo}}
  {{#linkTo dynamic}}link{{/linkTo}}

Since arrayProxy is an empty ArrayProxy, the else part gets called and the second linkTo is rendered.
Hence, DynamicRoute's serialize hook gets undefined as the model argument.

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download