-- Fabrice Terrasson <[EMAIL PROTECTED]> wrote
(on Thursday, 03 July 2008, 03:10 PM +0200):
> Matthew Weier O'Phinney a écrit :
> > -- Fabrice Terrasson <[EMAIL PROTECTED]> wrote
> > (on Wednesday, 02 July 2008, 06:33 PM +0200):
> >
> > ....
> >
>
> > Well, you've got one big problem here: autoCompleteDojo() isn't yet
> > wrapping Zend_Dojo_Data, so you'll get an inaccurate and invalid
> > structure as you show below.
> >
> > For now, until I refactor autoCompleteDojo(), do this in your action
> > instead:
> >
> >
> > $this->_helper->viewRenderer->setNoRender(true);
> > $this->_helper->layout->disableLayout(true);
> > $response = $this->getResponse();
> > $response->setHeader('Content-Type', 'application/json')
> > ->setBody($f->toJson());
> >
> > I'll be refactoring autoCompleteDojo() in the coming week to allow
> > passing Zend_Dojo_Data objects, as well as to consume Zend_Dojo_Data to
> > create the payload when other types are passed to it.
> >
> >
> I was confused by this helper :)
>
> Thanks for your help !
> dojo.data.ItemFileReadStore seems to accept by default json like:
> {"identifier":"produit",
> "items":[
> {"id":"1","produit":"pomme"},
> {"id":"2","produit":"orange"},
> {"id":"3","produit":"poire"},
> {"id":"4","produit":"abricot"}
> ]}
> (each item in curly brackets).
>
> Zend_Dojo_Data->toJson() returns a json like:
> {"identifier":"produit",
> "items":{
> "pomme":{"id":"1","produit":"pomme"},
> "orange":{"id":"2","produit":"orange"},
> "poire":{"id":"3","produit":"poire"},
> "abricot":{"id":"4","produit":"abricot"}
> }}
> (no simple bracket around items [ ] and a sole value facing item)
> and the dojo store (dojo.data.ItemFileReadStore) is empty.
Aha -- good catch! I can fix that easily, and will do so momentarily.
Thanks!
> bypassing Zend_Dojo_Data like that, fill the dojo store correctly :
>
> $p= new Catalogue();
> $rows= $p->fetchAll()->toArray();
>
> /*
> $f= new Zend_Dojo_Data();
> $f->setIdentifier('produit');
> $f->addItems( $rows );
> */
>
> $array = array(
> 'identifier' => 'produit',
> 'items' => $rows,
> );
>
> $f= Zend_Json::encode( $array );
> // context is json
> $this->getResponse()->setBody( $f );
>
> I am using firebug to watch the json Response + aol cdn (
> $this->dojo->enable() ).
--
Matthew Weier O'Phinney
Software Architect | [EMAIL PROTECTED]
Zend Framework | http://framework.zend.com/