0
votes

My backed has a list of objects, at api/vehicles:

{ 
    "vehicles" : [
        { 
            "id" : "car" ,
            "nr-doors" : 4,
            ...
        },
        {
            "id" : "ship",
            "nr-sails" : 3
            ...
        },
        {
            "id" : "train",
            "seats-per-wagon" : 30,
            ...
        }
    ]
}

All vehicles have only the "id" field in common, and they have several specific properties. There is only one vehicle of each kind. The IDs are fixed and already known. I would like to have a template to display/edit the car's properties. How can I relate a specific id (like "car") with a model/template/controller/view?

The problem that I have is that in ember and ember-data, the IDs at a certain URL refer to objects of the same kind, which can be handled by the same route/view/controller/model. In my application, this is not the case: each ID must be handled in a completely different controller/model/view/template.

How can I do this?

1

1 Answers

1
votes

each ID must be handled in a completely different controller/model/view/template

Are you sure? This would be a radical departure from not just ember but any model-view-controller architecture.

If you really want to accomplish this, I would suggest the following:

Start by creating the templates and routes you want to have

App.Router.map(function() {
  this.route("car");
  this.route("ship");
  this.route("train");
});

App.CarRoute = Ember.Route.extend({
  model: function() {
    return App.Vehicle.find('car');
  }
});

App.CarController = Ember.ObjectController.extend({
  //add any custom fx related to cars here
});

// Now define handlebars template for car and if needed a CarView