[Catalyst] Using Jquery UI Autocomplete widget with
Catalyst::View::JSON
Lee Aylward
lee at laylward.com
Mon Apr 26 15:08:25 GMT 2010
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 = $c->model('DB::Somedata')->search_rs({...}, {...});
>
> $c->stash->{json} = [
> map { id => $_->id, label => $_->name } ($result_set->all)
> ];
>
> Or a bit more verbose:
>
> foreach my $result ($result_set->all) {
> push(@{$c->stash->{json}}, { id => $result->id, label =>
> $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/HashRefInflator.pm
--
Lee Aylward
More information about the Catalyst
mailing list