Hi
We use the JS API a bit, mostly for backend admin tasks, lot of which involve getting and setting metadata.
What Bart suggested (using an asset listing) is what we generally do.
The asset listing can be set up to return specific data or accept dynamic parameters for what data it should return.
The listing format is structured to return a JSON array.
In the frontend JS get the JSON using an ajax call and begin iterating over the results when it’s received, for example, by calling Matrix JS API functions to update the metadata as needed.
For example:
Default format something like:
%asset_position^gt:1:,%{"assetid":"%asset_assetid%","something":"%asset_metadata_Something^json_encode%"}
Page contents:
[%asset_listing^replace:(\s+): %]
You can also set a dynamic root node/asset selection parameter as well if you want to make it more flexible.
Make sure content containers are raw html and there are no designs/layouts that are going to add html to the data. Can also add a design with a json mime type if needed.
Then just make a standard ajax request and iterate over the results.
Thanks
Peter