[jweb] window.max.setDict doesn't write JSON data to dict
Hello again, in my jweb html file, in script section there is a code snippet which should be able to write to dict named MatrDict. Debugging shows that the matrData json produces as it should, copying the json from console to dict also displays it correctly in dict.view, changing matrData to something simple as { a: "1", b: "2", c: "3"} also works fine and it writes to the dict successfully, however trying to set the matrData won't give any results, why?
async updateMatrix(id, edges) {
const matrix = this.matrices.get(id);
if (matrix) {
// Store edges directly as {start, end} pairs
matrix.edges = new Set(edges.map(edge => ({
start: { x: edge.start.x, y: edge.start.y },
end: { x: edge.end.x, y: edge.end.y }
})));
const jsonData = {
matrices: Array.from(this.matrices.entries()).reduce((obj, [key, value]) => {
obj[key] = {
...value,
edges: Array.from(value.edges) // Convert Set to Array
};
return obj;
}, {})
};
// console.log(jsonData) => success
const matrData = JSON.stringify(jsonData.matrices)
// console.log(matrData) => success
window.max.getDict("MatrDict", (dict) => {
window.max.setDict("MatrDict", matrData)
})
return true;
}
return false;
the json looks like this:
{
"1": {
"id": 1,
"edges": [
{
"start": {
"x": 0,
"y": 0
},
"end": {
"x": 1,
"y": 3
}
},
{
"start": {
"x": 1,
"y": 3
},
"end": {
"x": 2,
"y": 0
}
},
{
"start": {
"x": 2,
"y": 0
},
"end": {
"x": 3,
"y": 1
}
}
],
"size": {}
},
"2": {
"id": 2,
"edges": [
{
"start": {
"x": 2,
"y": 3
},
"end": {
"x": 2,
"y": 0
}
},
{
"start": {
"x": 2,
"y": 0
},
"end": {
"x": 0,
"y": 1
}
},
{
"start": {
"x": 2,
"y": 0
},
"end": {
"x": 4,
"y": 3
}
},
{
"start": {
"x": 4,
"y": 3
},
"end": {
"x": 2,
"y": 4
}
},
{
"start": {
"x": 2,
"y": 4
},
"end": {
"x": 1,
"y": 2
}
},
{
"start": {
"x": 4,
"y": 1
},
"end": {
"x": 3,
"y": 2
}
}
],
"size": {}
},
"3": {
"id": 3,
"edges": [
{
"start": {
"x": 0,
"y": 3
},
"end": {
"x": 1,
"y": 0
}
},
{
"start": {
"x": 1,
"y": 0
},
"end": {
"x": 2,
"y": 3
}
},
{
"start": {
"x": 2,
"y": 3
},
"end": {
"x": 3,
"y": 1
}
},
{
"start": {
"x": 3,
"y": 1
},
"end": {
"x": 4,
"y": 2
}
}
],
"size": {}
}
}
Wow, apparently it worked, strange though, I am used to stringify jsons before setting them to dicts
I'm glad it went quickly ;-)