Hi monks

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!

UPDATE:

I use JSON module to create data for jqGrid manually, it display the data well.

I posted the similar question on stackflow first, but no answer. Maybe here is better place. ;)

closed! the author of the module gave me answer.





I am trying to improve my English skills, if you see a mistake please feel free to reply or /msg me a correction


In reply to correct way to Catalyst::View::JSON? by xiaoyafeng

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.