Ember model to json

后端 未结 12 1371
北恋
北恋 2020-12-13 13:55

I am looking for an efficient way to translate my Ember object to a json string, to use it in a websocket message below

/*
 * Model
 */

App.node = Ember.Obj         


        
12条回答
  •  醉话见心
    2020-12-13 14:48

    Ember Data Model's object counts with a toJSON method which optionally receives an plain object with includeId property used to convert an Ember Data Model into a JSON with the properties of the model.

    https://api.emberjs.com/ember-data/2.10/classes/DS.Model/methods/toJSON?anchor=toJSON

    You can use it as follows:

    const objects = models.map((model) => model.toJSON({ includeId: true }));
    

    Hope it helps. Enjoy!

提交回复
热议问题