FAQ
Hi,
?? ? I'm using Catalyst::View::JSON and
Catalyst::TraitFor::Controller::jQuery::jqGrid to retrieve JSON data
to front page. Below is the code concerned (copy much partially from
Catalyst::TraitFor::Controller::jQuery::jqGrid example):

package UW::Controller::Site;
use utf8;
use Moose;
use namespace::autoclean;
BEGIN {extends 'Catalyst::Controller'; }
with 'Catalyst::TraitFor::Controller::jQuery::jqGrid';

sub json : Local{
my ($self, $c) = @_;
my $merchant_rs = $c->model('WindyDB::Merchant')->search({});
$merchant_rs = $self->jqgrid_page($c, $merchant_rs);
? ?my $row = 0;
my @row_data;
my $i = 0;
while (my $mer = $merchant_rs->next){
$i ++;
my $mer_id = $mer->mer_id;
$c->log->debug($mer_id);
my $single_row = {
'id' ? => $i,
'cell' => [
'id' => $mer->mer_id,
'name' => $mer->mer_name,
],
};
push @row_data, $single_row;

}

$c->log->debug( @row_data);
$c->stash->{json_data}->{rows} = \@row_data;
$c->stash->{current_view} ?= 'JSON';
}


But I found the format is a little weird :
{"current_view":"JSON","json_data":{"page":0,"records":"8","rows":[{id:1,
cell:["test1","6"]},{id:2, cell["test2","7"]}],"total":1}}
Actually, as jqGrid doument, data format should be:
{ total: "xxx", page: "yyy", records: "zzz", rows : [ {id:"1",
cell:["cell11", "cell12", "cell13"]}, {id:"2", cell:["cell21",
"cell22", "cell23"]}, ... ] }

Does That means "current_view" and "json_data" pairs are surplus? So
is there a way to remove current_view and json_data before server
ship?
or does I use the modules incorrectly? I'm new to Catalyst and jqGrid,
please help.
Any replies are really appreciated!

Search Discussions

  • Ian Docherty at Jun 28, 2010 at 6:24 am
    I suspect you have not configured your View::JSON correctly.

    Ensure you have it configured in your equivalent to MyApp.pm as follows.

    __PACKAGE__->config->{'View::JSON'} = {
    expose_stash => 'json_data',
    };

    and it should then do what you want.

    Regards
    Ian

    On 28/06/2010 05:17, Xiao Yafeng wrote:
    Hi,
    I'm using Catalyst::View::JSON and
    Catalyst::TraitFor::Controller::jQuery::jqGrid to retrieve JSON data
    to front page. Below is the code concerned (copy much partially from
    Catalyst::TraitFor::Controller::jQuery::jqGrid example):

    package UW::Controller::Site;
    use utf8;
    use Moose;
    use namespace::autoclean;
    BEGIN {extends 'Catalyst::Controller'; }
    with 'Catalyst::TraitFor::Controller::jQuery::jqGrid';

    sub json : Local{
    my ($self, $c) = @_;
    my $merchant_rs = $c->model('WindyDB::Merchant')->search({});
    $merchant_rs = $self->jqgrid_page($c, $merchant_rs);
    my $row = 0;
    my @row_data;
    my $i = 0;
    while (my $mer = $merchant_rs->next){
    $i ++;
    my $mer_id = $mer->mer_id;
    $c->log->debug($mer_id);
    my $single_row = {
    'id' => $i,
    'cell' => [
    'id' => $mer->mer_id,
    'name' => $mer->mer_name,
    ],
    };
    push @row_data, $single_row;

    }

    $c->log->debug( @row_data);
    $c->stash->{json_data}->{rows} = \@row_data;
    $c->stash->{current_view} = 'JSON';
    }


    But I found the format is a little weird :
    {"current_view":"JSON","json_data":{"page":0,"records":"8","rows":[{id:1,
    cell:["test1","6"]},{id:2, cell["test2","7"]}],"total":1}}
    Actually, as jqGrid doument, data format should be:
    { total: "xxx", page: "yyy", records: "zzz", rows : [ {id:"1",
    cell:["cell11", "cell12", "cell13"]}, {id:"2", cell:["cell21",
    "cell22", "cell23"]}, ... ] }

    Does That means "current_view" and "json_data" pairs are surplus? So
    is there a way to remove current_view and json_data before server
    ship?
    or does I use the modules incorrectly? I'm new to Catalyst and jqGrid,
    please help.
    Any replies are really appreciated!

    _______________________________________________
    List: Catalyst@lists.scsys.co.uk
    Listinfo: http://lists.scsys.co.uk/cgi-bin/mailman/listinfo/catalyst
    Searchable archive: http://www.mail-archive.com/catalyst@lists.scsys.co.uk/
    Dev site: http://dev.catalyst.perl.org/
  • Ian Docherty at Jun 28, 2010 at 6:26 am
    If you think that either the code or documentation of
    Catalyst::TraitFor::Controller::jQuery::jqGrid is wrong then drop me an
    email please.

    Regards
    Ian
    On 28/06/2010 05:17, Xiao Yafeng wrote:
    Hi,
    I'm using Catalyst::View::JSON and
    Catalyst::TraitFor::Controller::jQuery::jqGrid to retrieve JSON data
    to front page. Below is the code concerned (copy much partially from
    Catalyst::TraitFor::Controller::jQuery::jqGrid example):

    package UW::Controller::Site;
    use utf8;
    use Moose;
    use namespace::autoclean;
    BEGIN {extends 'Catalyst::Controller'; }
    with 'Catalyst::TraitFor::Controller::jQuery::jqGrid';

    sub json : Local{
    my ($self, $c) = @_;
    my $merchant_rs = $c->model('WindyDB::Merchant')->search({});
    $merchant_rs = $self->jqgrid_page($c, $merchant_rs);
    my $row = 0;
    my @row_data;
    my $i = 0;
    while (my $mer = $merchant_rs->next){
    $i ++;
    my $mer_id = $mer->mer_id;
    $c->log->debug($mer_id);
    my $single_row = {
    'id' => $i,
    'cell' => [
    'id' => $mer->mer_id,
    'name' => $mer->mer_name,
    ],
    };
    push @row_data, $single_row;

    }

    $c->log->debug( @row_data);
    $c->stash->{json_data}->{rows} = \@row_data;
    $c->stash->{current_view} = 'JSON';
    }


    But I found the format is a little weird :
    {"current_view":"JSON","json_data":{"page":0,"records":"8","rows":[{id:1,
    cell:["test1","6"]},{id:2, cell["test2","7"]}],"total":1}}
    Actually, as jqGrid doument, data format should be:
    { total: "xxx", page: "yyy", records: "zzz", rows : [ {id:"1",
    cell:["cell11", "cell12", "cell13"]}, {id:"2", cell:["cell21",
    "cell22", "cell23"]}, ... ] }

    Does That means "current_view" and "json_data" pairs are surplus? So
    is there a way to remove current_view and json_data before server
    ship?
    or does I use the modules incorrectly? I'm new to Catalyst and jqGrid,
    please help.
    Any replies are really appreciated!

    _______________________________________________
    List: Catalyst@lists.scsys.co.uk
    Listinfo: http://lists.scsys.co.uk/cgi-bin/mailman/listinfo/catalyst
    Searchable archive: http://www.mail-archive.com/catalyst@lists.scsys.co.uk/
    Dev site: http://dev.catalyst.perl.org/
  • Xiao Yafeng at Jun 28, 2010 at 6:57 am
    it works. I've known what mistake I made. Thanks!
    BTW. remind users configuring expose_stash would be more friendly for
    new user like me. ;)
    On Mon, Jun 28, 2010 at 2:26 PM, Ian Docherty wrote:
    If you think that either the code or documentation of
    Catalyst::TraitFor::Controller::jQuery::jqGrid is wrong then drop me an
    email please.

    Regards
    Ian
    On 28/06/2010 05:17, Xiao Yafeng wrote:

    Hi,
    ? ? ?I'm using Catalyst::View::JSON and
    Catalyst::TraitFor::Controller::jQuery::jqGrid to retrieve JSON data
    to front page. Below is the code concerned (copy much partially from
    Catalyst::TraitFor::Controller::jQuery::jqGrid example):

    package UW::Controller::Site;
    use utf8;
    use Moose;
    use namespace::autoclean;
    BEGIN {extends 'Catalyst::Controller'; }
    with 'Catalyst::TraitFor::Controller::jQuery::jqGrid';

    sub json : Local{
    my ($self, $c) = @_;
    my $merchant_rs = $c->model('WindyDB::Merchant')->search({});
    $merchant_rs = $self->jqgrid_page($c, $merchant_rs);
    ? ?my $row = 0;
    my @row_data;
    my $i = 0;
    while (my $mer = $merchant_rs->next){
    $i ++;
    my $mer_id = $mer->mer_id;
    $c->log->debug($mer_id);
    my $single_row = {
    'id' ? => ?$i,
    'cell' => ?[
    'id' => ?$mer->mer_id,
    'name' => ?$mer->mer_name,
    ],
    };
    push @row_data, $single_row;

    }

    $c->log->debug( @row_data);
    $c->stash->{json_data}->{rows} = \@row_data;
    $c->stash->{current_view} ?= 'JSON';
    }


    But I found the format is a little weird :
    {"current_view":"JSON","json_data":{"page":0,"records":"8","rows":[{id:1,
    cell:["test1","6"]},{id:2, cell["test2","7"]}],"total":1}}
    Actually, as jqGrid doument, data format should be:
    { total: "xxx", page: "yyy", records: "zzz", rows : [ {id:"1",
    cell:["cell11", "cell12", "cell13"]}, {id:"2", cell:["cell21",
    "cell22", "cell23"]}, ... ] }

    Does That means "current_view" and "json_data" pairs are surplus? So
    is there a way to remove current_view and json_data before server
    ship?
    or does I use the modules incorrectly? I'm new to Catalyst and jqGrid,
    please help.
    Any replies are really appreciated!

    _______________________________________________
    List: Catalyst@lists.scsys.co.uk
    Listinfo: http://lists.scsys.co.uk/cgi-bin/mailman/listinfo/catalyst
    Searchable archive:
    http://www.mail-archive.com/catalyst@lists.scsys.co.uk/
    Dev site: http://dev.catalyst.perl.org/

    _______________________________________________
    List: Catalyst@lists.scsys.co.uk
    Listinfo: http://lists.scsys.co.uk/cgi-bin/mailman/listinfo/catalyst
    Searchable archive: http://www.mail-archive.com/catalyst@lists.scsys.co.uk/
    Dev site: http://dev.catalyst.perl.org/

Related Discussions

Discussion Navigation
viewthread | post
Discussion Overview
groupcatalyst @
categoriescatalyst, perl
postedJun 28, '10 at 4:17a
activeJun 28, '10 at 6:57a
posts4
users2
websitecatalystframework.org
irc#catalyst

2 users in discussion

Ian Docherty: 2 posts Xiao Yafeng: 2 posts

People

Translate

site design / logo © 2022 Grokbase