On Dec 28, 2010, at 9:52 AM, David Ringsmuth wrote:
> I'd prefer to create a map and use Active4D's addRowSet or addSelection
> macros. But these don't seem offer the required way to format the json. Part
> of my requirement includes a call-back option and a relate-one feature.
>
> It would be perfect (Aparajita) if I could map into an array:
> $map{"id"} := ->[employee]id
> $map{"data"} := ->[employee]dob + >[employee]firstname +
> ->[employee]lastname
Seem that the below (which is just some test code pulled from a qry_select_many
and index script), is a way of doing it with rowsets. Although rolling your own
may be easier.
<%
all records([instructor])
reduce selection([instructor]; 30)
$map := """
id: [instructor]id;
data: `$data_array`
"""
$callback := """
array text($data_array;0)
$data_array{} := [instructor]fullname
$data_array{} := [instructor]employer
$data_array{} := [instructor]status
$data_array{} := [instructor]city
"""
$qryinstructors := RowSet.newFromSelection(->[instructor]; $map;0;
$callback)
$json := a4d.json.new
array longint($rows;0)
$row := $qryinstructors->getRow
while ($qryinstructors->next)
$rows{} := new collection("id";$row{"id"};"data";$row{"data"})
end while
$json->addArray("rows";$rows)
$json->write
%>
You might have to modify a4d.json addArray method case statement for numerics
to: (I submitted a feature request to allow arrays of objects/collections)
:($type >= 14) & ($type <= 16) // numeric
for each ($inArray; $val)
if ($type = 16) & is a collection($val)
text to
blob(encodeCollection($val) + ","; $self{"_rep"}; text without length; *)
else
text to blob(string($val) +
","; $self{"_rep"}; text without length; *)
end if
end for each
Steve Alex
"rows":
[
{
"data":
[
"Jones,
Vickie",
"",
"Active",
""
],
"id":819
},
{
"data":
[
"Glover,
Alicia",
"",
"Active",
""
],
"id":820
},
{
"data":
[
"Peters,
James \"Chief\"",
"",
"Active",
"Montgomery"
],
"id":36
}
]
_______________________________________________
Active4D-dev mailing list
[email protected]
http://mailman.aparajitaworld.com/mailman/listinfo/active4d-dev
Archives: http://mailman.aparajitaworld.com/archive/active4d-dev/