I'm working with an API that returns an attribute that is an object e.g. interest:
{
"data": [
{
"type": "accounts",
"attributes": {
"accrued_interest": 0,
"interest": {
"rate_terms": "FIXED",
"charge_frequency": "ANNUALIZED",
}
},
}
]
}
I'm using ES6 to create a JSORM model:
const Account = Base.extend({
static: {
jsonapiType: 'accounts'
},
attrs: {
accruedInterest: attr(),
interest: attr(),
}
});
(Base is a JSORMBase I've extended to centralise the API endpoint and Auth config.)
Is there a way for JSORM to parse the interest attribute, so that model.interest.rateTerms would be available? In that example above, it's only available as model.interest.rate_terms.
I've also tried interest: attr({ type: Interest }) where Interest is a class I've created to contain this data.
A pointer to the recommended way of doing this would be very helpful. Thanks!
I'm working with an API that returns an attribute that is an object e.g.
interest:{ "data": [ { "type": "accounts", "attributes": { "accrued_interest": 0, "interest": { "rate_terms": "FIXED", "charge_frequency": "ANNUALIZED", } }, } ] }I'm using ES6 to create a JSORM model:
(
Baseis aJSORMBaseI've extended to centralise the API endpoint and Auth config.)Is there a way for JSORM to parse the
interestattribute, so thatmodel.interest.rateTermswould be available? In that example above, it's only available asmodel.interest.rate_terms.I've also tried
interest: attr({ type: Interest })where Interest is a class I've created to contain this data.A pointer to the recommended way of doing this would be very helpful. Thanks!