This is how I'm doing it:
const Document = Parse.Object.extend('Document')
const query = new Parse.Query(Document)
let result = {}
query.get(id, {
success: function (object) {
result = object.toJSON()
console.log(result)
},
error: function (object, error) {
alert(`Error: ${error.code} ${error.message}`)
}
})
console.log(result)
return result
The first console.log(result) outputs the object:
Object {content: "trstrtrts", createdAt: "2016-01-17T11:20:30.694Z", title: "Document 2", updatedAt: "2016-01-17T11:20:30.694Z", wordCount: "3000"…}
But the second one returns nothing. What's the correct way of returning an object from a Parse query?
EDIT:
Based on Anon's answer I tried this:
store.js:
store.first = (id) => {
var query = new Parse.Query(Document)
return query.get(id)
}
export default store
main.js:
store.first(to.params.id).then((document) => {
console.log(document.toJSON())
return document.toJSON()
})
But I get the following error:
Uncaught TypeError: Object function ParsePromise() { _classCallCheck(this, ParsePromise); this._resolved = false; this._rejected = false; this._resolvedCallbacks = []; this._rejectedCallbacks = []; } has no method 'all'