Answer the question
In order to leave comments, you need to log in
Unloading data from resources in JS - how to implement it correctly?
Sorry if the question seems confusing to you. There is a site on MODx Revo that has many (over a thousand) resources.
Task: unload some fields of most resources (namely, pagetitle and url) into some convenient format and insert them into a block with javascript code on the page so that they (this data) can then be manipulated. In modex I use the pdoTools component. For the structure of the unloaded data, I didn’t think of anything better than using an object, inside which is an array with a single key objects
, which will store objects with keys title
and url
, whose values will, respectively, be taken from resources.
Do I understand correctly that I need to take the pdoResources snippet and use it to select the necessary resources, and ensure the correct structure using a chunk. For example,
Calling a snippet in a template (conditional):
<script>
var myArray = {
"objects": [
]
};
</script>
{
"title":"",
"url":""
},
@INLINE
(although, with this approach, you can also record a regular chunk as well). So. Is this approach normal, or is there something more primitive/understandable? In fact, it suits me, I just would like to know how crooked my version is and what other options for solving this problem are there? var myArray = {
"objects": [
{
"pagetitle": "название 1",
"url": "http://ya1.ru"
},
{
"pagetitle": "название 2",
"url": "http://ya2.ru"
},
{
"pagetitle": "название 3",
"url": "http://ya3.ru"
}
]
};
Answer the question
In order to leave comments, you need to log in
In general, it was realized exactly as I expected. Since there are no answers, I close the question through my own answer. If you want to know any comments, ask questions, then write in the comments, or by mail.
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question