New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Cannot read property 'documentClass' of undefined #35
Comments
Somehow, the document still open after the save() function. update codes: addWhiteboard () {
this._indexWb = this.whiteboards.push(Whiteboard.create());
};
addShape (data) {
var shape = Shape.create({
type: data.type
});
this._indexShape = this.whiteboards[this._indexWb-1].shapes.push(shape);
};
getShape () {
return this.whiteboards[this._indexWb-1].shapes[this._indexShape-1].toJSON();
}
addPoint (point) {
this.whiteboards[this._indexWb-1].shapes[this._indexShape-1].points.push(Point.create({
x: point.x,
y: point.y
}))
} Now they are part of the document. Am I doing something wrong? |
I am, at this time, not able to update none of the index. Even if I set them in those function, there are resetting. |
Hi Michael, A couple quick notes:
When you say "The problem I'm facing is, when I update an array inside another array, I can't access that document anymore", do you mean this line? classroom.whiteboards[classroom.whiteboards.length-1].shapes.push(shape); I'll do some testing and see if I can find any problems. It might be helpful if you could post the code for the Thanks. |
Whiteboard, Shape and Point are EmbeddedDocument. I tried to save them, but it throws "save()" it's undefined. class Classroom extends Document {
constructor() {
super();
this.className = {
type: String,
required: true
};
this.date = {
type: Date,
default: Date.now()
};
this.whiteboards = {
type: [Whiteboard],
default: [Whiteboard.create()]
};
this._indexWb = 0;
this._indexShape = -1;
}
get indexWb () {
return this._indexShape;
}
set indexWb (value) {
console.log('indexWb: '+value);
this._indexShape = value;
}
get indexShape() {
return this._indexShape;
}
set indexShape(value) {
console.log('indexShape: '+value);
this._indexShape = value;
}
addWhiteboard () {
this.indexWb = this.whiteboards.push(Whiteboard.create());
};
addShape (data) {
var shape = Shape.create({
type: data.type
});
this.indexShape = this.whiteboards[this.indexWb].shapes.push(shape);
};
getShape () {
return this.whiteboards[this.indexWb].shapes[this.indexShape].toJSON();
}
addPoint (point) {
this.whiteboards[this.indexWb].shapes[this.indexShape].points.push(Point.create({
x: point.x,
y: point.y
}))
}
} This is the current class of the Classroom document. I change things to test. There is no way to update either of the _index, not even with the index get and set (BTW, because of the getters and setters being publics, now the document save them). I will just move on and use standard Document. I think that may solve the problem. I'll let you know. Thanks! |
Ah, okay, I didn't realize Whiteboard, Shape and Point were EmbeddedDocuments. That makes a lot more sense. I think you may have found an issue with saving nested arrays, so I'll look in to it. Thanks! |
I think it maybe related to a nested arrays of EmbeddedDocuments. I'm unable right now to test it. But next week or so, I'll help you properly reporting a playable scenario. |
Found the issue. You're right, there is a problem saving/loading deeply nested Thanks for pointing this out! |
Glad I could help. |
I'm doing an API RESTful with camo using nedb as datastorage. The problem I'm facing is, when I update an array inside another array, I can't access that document anymore.
If I restart the server and load the datastorage again, I can access the data again, even the updated one, so it does saved it. How ever, I doesn't seem to be able to read it after.
Here's my code:
To update:
To read:
successHandler and errorHandler, just send a response with 200 or 500 status, and jsonp of the document or the error.
Hope can help.
Thanks!
The text was updated successfully, but these errors were encountered: