1
votes


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

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(params.name);
  },

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

when arrayProxy is either [] or Ember.ArrayProxy.create(content: []), after clicking on the link:
the model hook will not get called, of course.
The serialize hook will get undefined as the model, 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 undefined?

2
I think that you need to show more code ... Do you have a route called ParentRoute? And where is defined the arrayProxy property of the template? What is your ember version?Marcio Junior
I'm using Ember 1.0.0. The serialize hook is called immediately after the template rendered to deduce the linkTo's href. The model hook not get called anyhow, so ParentRoute is not part of the problem.Shany
You will have to show the code related to your template with the linkTo.mavilein

2 Answers

0
votes

Not sure if is a typo mistake, but you are missing the return in the model hook:

model: function(params) {
  return this.modelFor("parent").find(params.name);
},

Without this, the serialize will always receive an undefined as model variable.

Serialize need the return too:

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

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

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

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.