Is there any way to create a batch of multiple records with a single POST request in Ember Data?

点点圈 提交于 2020-01-04 13:41:13

问题


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

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!