[Catalyst] Using Jquery UI Autocomplete widget with Catalyst::View::JSON

Ben van Staveren benvanstaveren at gmail.com
Mon Apr 26 15:23:39 GMT 2010


Used it but at the same time, doing my $hashref =3D { $row->get_columns } =

got me more or less the same effect for a lot less hassle :)

I actually do this for most my DB objects that get serialised to JSON, =

quite simple case of $c->stash->{json} =3D [ map { $_->get_columns } =

$rs->all ];

In a similar vein, I haven't yet really seen/heard any sort of "best =

practices" when it comes to Catalyst and JSON, so maybe I'm going about =

it all wrong but eh :)

Lee Aylward wrote:
> On Mon, 26 Apr 2010 16:33:31 +0700
> Ben van Staveren <benvanstaveren at gmail.com> wrote:
>
>   =

>> Probably not the most pretty one but:
>>
>> Given you have a resultset obtained with, say,
>>
>> my $result_set =3D $c->model('DB::Somedata')->search_rs({...}, {...});
>>
>> $c->stash->{json} =3D [
>>   map { id =3D> $_->id, label =3D> $_->name } ($result_set->all)
>>   ];
>>
>> Or a bit more verbose:
>>
>> foreach my $result ($result_set->all) {
>>   push(@{$c->stash->{json}}, { id =3D> $result->id, label =3D>
>> $result->name }); }
>>
>>    `
>>
>>     =

>
> I've also had good luck using DBIx::Class::RsultClass::HashRefInflator
> in the past. It doesn't give you quite as much control, but it may be
> enough for your needs.
>
> http://search.cpan.org/~frew/DBIx-Class/lib/DBIx/Class/ResultClass/HashRe=
fInflator.pm
>
>   =


-- =

Ben van Staveren
phone: +62 81 70777529
email: benvanstaveren at gmail.com

-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://lists.scsys.co.uk/pipermail/catalyst/attachments/20100426/05ec5=
880/attachment.htm


More information about the Catalyst mailing list