A
A
Alexey Sol2017-02-02 01:39:59
PHP
Alexey Sol, 2017-02-02 01:39:59

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 titleand 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>

JSONchunk : _
{
"title":"",
"url":""
},

Accordingly, the last chunk differs only in that there is no comma at the end. I think you can even shove it into @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?
I suppose that in my version, the result should be something like this:
Result
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

1 answer(s)
A
Alexey Sol, 2017-02-12
@NN-webmaster

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 question

Ask a Question

731 491 924 answers to any question