S
S
Sergey Miller2019-12-15 06:10:52
JavaScript
Sergey Miller, 2019-12-15 06:10:52

How to display the daughters of the desired resource modx api + ajax?

What am I trying to do?
There is a tree

-Родитель1 --дочка1 --дочка2
-Родитель2 --дочка1 --дочка2 --дочка2...

There are selects on the site, they have an over-dofiga option, each of which has an id (id = the correct resource id). These options are loaded into the select via pdoMenu. It is necessary that when choosing the nth option in this select, for the time being, the children of the selected option are loaded on Ajax into a certain #div.
Implementation:
0 Simple output of resources in select

1 I made a page on the site content.html
2 I made an empty template for this page
3 I inserted the snippet into the content of the page
4 The snippet itself:
$res = $modx->getObject('modResource', $_POST['id']);
return  $res->getMany('Children');

5 jQuery:
$('.inpts select#brand').on('change',function(e){
var id = $(this).find('option:selected').attr('data-id');
$.ajax({
type: "POST",
url: "content.html",
data: "id="+id,
success: function(content){
$(".inpts").html(content);
}
});
});


What do I end up getting?
Where the daughters of the desired resource should be displayed, the word " Array " is stupidly displayed.
What am I doing wrong?

I checked that this script works like this - instead of getMany ('Chidren') I specified get ('pagetitle') - as a result, the correct title is displayed, but there is some kind of trouble with daughters

Answer the question

In order to leave comments, you need to log in

1 answer(s)
S
Sergey Miller, 2019-12-15
@blackseabreathe

If someone helps.

$res = $modx->getObject('modResource', $_POST['id']);
$id = $res->get('id');
$depth = 1;
$ids = $modx->getChildIds($id, $depth);
$docs = $modx->getCollection('modResource', array(
'id:IN' => $ids
,'alias:!=' => 'f'
));
$output = '';
foreach ($docs as $doc) {
$output .= $doc->get('pagetitle') . '<br/>';
}
return $output;

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question