问题
var batch = [someRecord, someRecord, someRecord...]
batch.invoke('save');
If I have an array of 50 newly created records and then invoke save on that array, then Ember Data will make 50 POST requests. I would rather bulk them into a single request and handle that on the API for performance. Is there any way to do this?
Right now it appears I will have to implement this manually with ajax. But if there is a better way, please share.
回答1:
There used to be a bulkCommit
feature in ember-data on the RESTAdapter, but it was removed.
As a workaround for today, the only way I can think of sending multiple records to the server at the same time would be to create custom Adapter that knows how to serialize multiple records then include all of the records you want to serialize in an hasMany relationship on a model.
https://github.com/emberjs/data/issues/2845
So no, you'll need to implement your own solution in your own adapter (or just straight up make an ajax call from wherever if you're feeling naughty).
来源:https://stackoverflow.com/questions/31412839/is-there-any-way-to-create-a-batch-of-multiple-records-with-a-single-post-reques