EDIT: I misunderstood the question, so here's an updated version of my answer:
Firstly, I think you should switch to using ember data. Then fetching an employee by id will simply allow this.get("store").find("employee", id) called.
If you want to use simple ajax, I suggest creating a service that encapsulates the specifics (API endpoint URL, data format, etc.) and provides only simple methods for finding and updating models.
And finally, to match the βdata down, action upβ pattern, you should not update the model in this component. Instead, submit the action to the parent controller / component. For instance:
app/components/employee-selector.js (the component you are writing):
export default Ember.Component.extend({ actions: { updateId(id) { Ember.$.post("http://server.ip.com/api/v1/getEmployee", { id: params.id }.then((response) => { this.sendAction("select", response); }); } });
app/templates/new/it-request.hbs :
{{employee-selector select=(action "selectEmployee")}}
app/controllers/new/it-request.js :
export default Ember.Controller.extend({ actions: { selectEmployee(employeeData) { this.set("model.name", employeeData.name); this.set("model.position", employeeData.name); } } });
Old answer:
An idiomatic solution would be to do this in Route .
First you must add the route to app/router.js :
this.route("employees", function() { this.route("show", { path: ":id" }); }
Define the route in app/employees/show/route.js :
import Ember from "ember"; export default Ember.Route.extend({ model(params) { return new Ember.RSVP.Promise((resolve, reject) { Ember.$.post("http://server.ip.com/api/v1/getEmployee", { id: params.id }.then( (response) => { resolve(response) }, reject ); }); } });
(The only reason I wrapped everything in the new promise is to allow the response to be configured - just replace resolve(response) code that converts the raw response from the server and calls resolve with this converted version).
But if you have more communication with the API, and I believe that you will, I suggest you try using ember-data or any other data layer library for ember (possibly Orbit).
Or at the very least, write a service that abstracts all communication with the API and uses it wherever you use raw ajax requests.