[snip]On 3/27/2012 12:21 AM, Robert Cummings wrote:
I think you need two things... the recursive post processor that
removes the string indexes for the children. And then a function that
creates a JavaScript array expression from an object or array. The
question I have for you... is given the following array structure that
might be generated from my previous code:
<?php
array
(
'exec-001' => array
(
'name' => 'exec-001',
'children' => array
(
'sub-exec-011' => array
(
'name' => 'sub-exec-011',
'children' => array
(
'sub-sub-exec-111' => array
(
'name' => 'sub-sub-exec-111',
'children' => array()
),
'sub-sub-exec-112' => array
(
'name' => 'sub-sub-exec-112',
'children' => array()
)
)
),
'sub-exec-012' => array
(
'name' => 'sub-exec-012',
'children' => array
(
'sub-sub-exec-121' => array
(
'name' => 'sub-sub-exec-121',
'children' => array()
),
'sub-sub-exec-122' => array
(
'name' => 'sub-sub-exec-122',
'children' => array()
)
)
)
)
),
'exec-002' => array
(
'name' => 'exec-002',
'children' => array
(
'sub-exec-021' => array
(
'name' => 'sub-exec-021',
'children' => array
(
'sub-sub-exec-211' => array
(
'name' => 'sub-sub-exec-211',
'children' => array()
),
'sub-sub-exec-212' => array
(
'name' => 'sub-sub-exec-212',
'children' => array()
)
)
),
'sub-exec-022' => array
(
'name' => 'sub-exec-022',
'children' => array
(
'sub-sub-exec-221' => array
(
'name' => 'sub-sub-exec-221',
'children' => array()
),
'sub-sub-exec-222' => array
(
'name' => 'sub-sub-exec-222',
'children' => array()
)
)
)
)
)
);
?>
On first blush, I think you want the following structure (from your
recent posts):
<?php
array
(
0 => array
(
'name' => 'exec-001',
'children' => array
(
0 => array
(
'name' => 'sub-exec-011',
'children' => array
(
0 => array
(
'name' => 'sub-sub-exec-111',
'children' => array()
),
1 => array
(
'name' => 'sub-sub-exec-112',
'children' => array()
)
)
),
1 => array
(
'name' => 'sub-exec-012',
'children' => array
(
0 => array
(
'name' => 'sub-sub-exec-121',
'children' => array()
),
1 => array
(
'name' => 'sub-sub-exec-122',
'children' => array()
)
)
)
)
),
1 => array
(
'name' => 'exec-002',
'children' => array
(
0 => array
(
'name' => 'sub-exec-021',
'children' => array
(
0 => array
(
'name' => 'sub-sub-exec-211',
'children' => array()
),
1 => array
(
'name' => 'sub-sub-exec-212',
'children' => array()
)
)
),
1 => array
(
'name' => 'sub-exec-022',
'children' => array
(
0 => array
(
'name' => 'sub-sub-exec-221',
'children' => array()
),
1 => array
(
'name' => 'sub-sub-exec-222',
'children' => array()
)
)
)
)
)
);
?>
Essentially, entries at the root and entries for the children are just
auto indexed array items but the actual entries in those arrays retain
the associative index structure for retrieval of the specific
information. let me know and I can probably whip you up something.
Robert that looks correct. Here is an example of the JSON that the guy
provided for me -
var json = {
id: "node02",
name: "0.2",
data: {},
children: [{
id: "node13",
name: "1.3",
data: {},
children: [{
id: "node24",
name: "2.4",
data: {},
children: [{
id: "node35",
name: "3.5",
data: {},
children: [{
id: "node46",
name: "4.6",
data: {},
children: []
}]
}, {
id: "node37",
name: "3.7",
data: {},
children: [{
id: "node48",
name: "4.8",
data: {},
children: []
}, {
id: "node49",
name: "4.9",
data: {},
children: []
}, {
id: "node410",
name: "4.10",
data: {},
children: []
}, {
id: "node411",
name: "4.11",
data: {},
children: []
}]
},
Of course he properly closes up the JSON. I inserted id's (just an
auto-incrementing number) and the data portion where needed. The name:
is the part that has been the result of what you did before.
--
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php