"the_mace" wrote:
What if I want to do something like this:
a=[ { metadata:{id:3}, name:"Betty"}, { metadata:{id:1}, name:"Carol"}, { metadata:{id:2}, name:"Anne"} ]
a.SortBy("metadata.id")
It doesn't work that way. There is no "metadata.id" key in these AAs, just "matadata" and "name". And also you cannot sort by "metadata" because the value of that is another AA - it can only sort by strings or numbers. Sorting the above by "name" will work however. If you want to be able to sort by a.metadata.id, you will have to pull it one level up - either by design or artificially, like i am doing here for the sake of demonstration:
Brightscript Debugger> a=[ { metadata:{id:3}, name:"Betty"}, { metadata:{id:1}, name:"Carol"}, { metadata:{id:2}, name:"Anne"} ]
Brightscript Debugger> for each elem in a: elem["metadata.id"] = elem.metadata.id: next: ? formatJSON(a)
[{"metadata":{"id":3},"metadata.id":3,"name":"Betty"},{"metadata":{"id":1},"metadata.id":1,"name":"Carol"},{"metadata":{"id":2},"metadata.id":2,"name":"Anne"}]
Brightscript Debugger> a.sortBy("metadata.id"): ? formatJSON(a)
[{"metadata":{"id":1},"metadata.id":1,"name":"Carol"},{"metadata":{"id":2},"metadata.id":2,"name":"Anne"},{"metadata":{"id":3},"metadata.id":3,"name":"Betty"}]