You are not logged in.
Hi all,
Is it possible to access a particular element in an array by specifying it's index?
Take the array below ... I want to be able to access element 2 (i.e. the 2018 year in a zero based array).
Some general Mustache pages suggest to use syntax line this {{Report.2}}, but that doesn't seem to work.
Any ideas or suggestions would be greatly appreciated?
"Report":
[
{
"ClassName": "TSQLBreederPerformanceLine",
"ID": 0,
"Year": 2020,
"Branded": 0,
"Breeders": 26672,
"BrandingRate": 0
},
{
"ClassName": "TSQLBreederPerformanceLine",
"ID": 0,
"Year": 2019,
"Branded": 10492,
"Breeders": 22577,
"BrandingRate": "46.4720733489835"
},
{
"ClassName": "TSQLBreederPerformanceLine",
"ID": 0,
"Year": 2018,
"Branded": 11273,
"Breeders": 22103,
"BrandingRate": "51.0021264081799"
},
{
"ClassName": "TSQLBreederPerformanceLine",
"ID": 0,
"Year": 2017,
"Branded": 10935,
"Breeders": 18961,
"BrandingRate": "57.671008913032"
}
]
Cheers.
Vernon.
Offline
In the current implementation, {{Report.2}} should search for a "2" field in the "Report" object, or indeed return the Report[2] if "Report" is an array.
At least, this is what should happen.
Could you debug and see why TSynMustacheContextVariant.GetValueFromContext() doesn't reach TDocVariant.IntGet() which should call TDocVariantData.RetrieveValueOrRaiseException() then TDocVariantData.GetValueIndex() to detect it is a TDocVariant array and return the 3rd item?
Note that this is not a standard mustache syntax at all.
Offline
Thanks ab.
I am not using the latest version of Mormot, so I will update and try again.
Cheers.
Vernon.
Offline