samedi 8 octobre 2016

Ember 2.8: 'Stringify' an array of objects in order to store it in a model's attributes list

So let's say I have a model for a Game, and each Game has associated Game Cards. I would have a model like this:

Game.js

import DS from 'ember-data';

export default DS.Model.extend({
    gamecards: DS.attr('string');
});

and in that gamecards attribute i would like to somehow convert an array of objects into string form in order to store it:

 //for simplicity, assume each empty object has card attributes like 'suit', or 'value'
    arrayOfGamecards = [//array of gamecard objects];

And then I could create an instance of Game which has:

gameCards: '[//array of gamecard objects]'

Ideally, I would also like to 'destringify' this array so I can do stuff with the objects inside of it. Is something like this possible with Ember?




Aucun commentaire:

Enregistrer un commentaire