Creating a 2D map array in QML?
-
wrote on 30 Sept 2020, 13:36 last edited by E106JZ
I'm not that well versed in JavaScript but I was trying to create a basic 2D map array with two keys (a string and integer) for accessing the value like this:
var array = {} for (var x=0; x<5; x++) { array["test"][x] = x }
But this gives me a TypeError: Type error on the array line when I run this code. How can I create a map like this at runtime and access it using a string and integer index using QML?
Thanks
-
I'm not that well versed in JavaScript but I was trying to create a basic 2D map array with two keys (a string and integer) for accessing the value like this:
var array = {} for (var x=0; x<5; x++) { array["test"][x] = x }
But this gives me a TypeError: Type error on the array line when I run this code. How can I create a map like this at runtime and access it using a string and integer index using QML?
Thanks
Hi,
@E106JZ said in Creating a 2D map array in QML?:
array["test"][ x ] = x
You are using it as if it was a dict of dict which is wrong. If you want to do it like that you have to make the content of
array["test"]
a dict before filling it.
1/2