Closed thipages closed 4 years ago
Hello,
This question has been answered in the Common questions section of the website: http://objectmodel.js.org/#common-questions
How should I deal with circular references in my model definitions ?
const A=Model(
{
id:Number,
children:ArrayModel(undefined)
}
);
A.definition.children.definition = A
Thank you! Here is a corresponding example
const A=Model(
{
id:Number,
children:ArrayModel(undefined)
}
);
A.definition.children.definition=A;
const qA=(id)=>A({id,children:[]});
const a1=qA(1);
const a2=qA(2);
const a3=qA(3);
a1.children=[a2,a3];
a2.children=[a1];
console.log(a1.children[0].id); // returns 2
Hi, I would like to define the model as a property as well Obviously, the code below is not working.
I can trick it by replacing children by ArrayModel(Number), Number representating an A id Did I miss something? Thank you.