Last active
November 21, 2023 08:35
-
-
Save nickjacob/2314faf0a01b514f16afe61ac7288183 to your computer and use it in GitHub Desktop.
How to convert an Ember object to a regular javascript object
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// an Ember.Object is typeof 'function'/a class | |
// which can make serialization difficult (e.g., there are issues passing | |
// to jQuery's serialization | |
// using Object.assign | |
// (& es6 syntax) | |
Ember.Object.reopen({ | |
toNative() { | |
return Object.assign({}, this); | |
}, | |
toJson() { | |
return JSON.stringify(this.toNative()); | |
} | |
}); | |
// an example obj | |
const em = Ember.Object.create({ data: [1, 2, 3] }); | |
$.ajax({ | |
type: 'GET', | |
url: '/api', | |
data: em.toNative() | |
}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment