I am currently utilizing CakePHP to execute a query on my database table 'Task', which consists of columns like project_id, id, parent_id, title, and description. The code in my controller that handles the query looks like this:
$query= $this->Task->find('threaded', array(
'conditions' => array(
'Task.project_id' => 83,
),
'fields' => array(
'Task.id',
'Task.title',
'Task.parent_id',
)
));
//Pass the result to the view
$this->set('query', $query);
When I try to decode the JSON in my view using the following snippet:
<?php echo json_encode($simple); ?>
The resulting JSON structure is as follows:
[
{
"Task": {
"id": "475",
"title": "Have a Picnic",
"parent_id": "0"
},
"children": [
{
"Task": {
"id": "476",
"title": "Drive/Hike to Mountains",
"parent_id": "475"
},
"children": []
}
]
}
In order for JS JIT SpaceTree to function properly, it requires a different structure, similar to the one shown below:
{
"id": "aUniqueIdentifier",
"name": "usually a nodes name",
"data": [
{key:"some key", value: "some value"},
{key:"some other key", value: "some other value"}
],
children: [/* other nodes or empty */]
}
However, I am uncertain about how to adjust the current output or modify my query to achieve the required structure. Additionally, I have experimented with both 'threaded' and 'list' find() types but encountered the same structure. Any guidance on this matter would be greatly appreciated!