问题
When bootstrapping Ember-data model objects with existing JSON that is not from a remote AJAX call, do I have to make the following 2 calls:
App.store.load(App.Account, data);
var account = App.store.find(App.Account, data.id);
Is it not possible to create the Object in one step, similar to calling setProperties
on an existing Ember object?
Also, how would this work for creating a collection of Ember model objects? For example:
var users = App.get('users');
App.store.loadMany(App.User, users);
this.set('content', App.store.findMany(App.User, users.mapProperty('id').uniq()));
The above seems wrong. How can I create these objects from existing JSON objects?
回答1:
Seems ok to me, as store.load*
returns something else than model objects (loaded ids
& clientIds
).
So far, I think there is no alternative.
来源:https://stackoverflow.com/questions/10887944/ember-data-bootstrapping-model-objects