-- sktib <[email protected]> wrote
(on Friday, 06 February 2009, 05:27 PM -0800):
>
> I played around with the Json a little and realized that if I change the Json
> to
>
> { identifier: 'id',
> items:[{"id":"1","name":"XBox"},{"id":"2","name":"XBox
> 360"},{"id":"3","name":"Sony PSP"},{"id":"4","name":"Playstation
> 3"},{"id":"5","name":"Playstation 2"},{"id":"6","name":"PC
> Games"},{"id":"7","name":"Nintendo
> Wii"},{"id":"8","name":"GameCube"},{"id":"9","name":"Nintendo
> DS"},{"id":"10","name":"Nintendo GBA"}]}
>
> NOTE - I added the "{ identifier: 'id', items: .... }", saved that to a file
> and read from that into my datastore for ComboBox, it works fine.
>
> So how do I make Zend_Json to spit out Json with "{ identifier: 'id', items:
> .... }" added?
Use Zend_Dojo_Data, which was built precisely for this purpose. :)
Simply do the following:
$data = new Zend_Dojo_Data('id', $object->fetchAll(), 'name');
echo $data;
I'm assuming that the "fetchAll()" you referenced in the earlier post
was a call to a database adapter or a Zend_Db_Table object; either way,
Zend_Dojo_Data is smart enough to figure it out.
As some background, the ComboBox and FilteringSelect widgets expect a
dojo.data payload in order to build the options for autocompletion.
dojo.data is an abstracted JSON data format used in Dojo for a variety
of widgets. Zend_Dojo_Data was created to create such structures.
> ---------------------------------------------
>
> sktib wrote:
> >
> > Hello Folks,
> >
> > I am working on XP with Zend 1.7.1.
> >
> > I am trying to get data from Database into a Dojo Combobox on my form -
> > transfering the data using JSON.
> >
> > I have the following Javascript on my phtml
> >
> > <script type="text/javascript">
> > dojo.addOnLoad(function(){
> > var pfStore = new dojo.data.ItemFileReadStore({url: "/test/games"});
> > var cb1 = new dijit.form.ComboBox({id: "platforms", name: "pf2",
> > value: "Xbox", store: pfStore, searchAttr: "name"}, "platforms");
> > });
> > </script>
> >
> > and the following html snippet
> > <td><input id="platforms"></td>
> >
> > When I click on the downarrow on the combobox, I see in FireBug the query
> > going out to /test/games but then it gives the following error
> >
> > "dijit.form.ComboBox: TypeError: this._arrayOfTopLevelItems is undefined"
> >
> > I look at the response in Firebug and I get the following JSON string.
> >
> > [{"id":"1","name":"XBox"},{"id":"2","name":"XBox
> > 360"},{"id":"3","name":"Sony PSP"},{"id":"4","name"
> >
> > :"Playstation 3"},{"id":"5","name":"Playstation 2"},{"id":"6","name":"PC
> > Games"},{"id":"7","name":"Nintendo
> >
> > Wii"},{"id":"8","name":"GameCube"},{"id":"9","name":"Nintendo
> > DS"},{"id":"10","name":"Nintendo GBA"
> >
> > }]
> >
> > To get this JSON, on the server side I do a fetchAll()->toArray() and then
> > apply Zend_Json::encode
> >
> > I don't understand what causes the error and why the "names" in response
> > data don't show up in my ComboBox. Sounds like I am overlooking something
> > simple/basic here.
> >
> > Appreciate any help/pointers.
> >
> > -S
> >
>
> ---------------------------------------------
>
> --
> View this message in context:
> http://www.nabble.com/Getting-JSON-data-in-ComboBox-gives-error-tp21882849p21884022.html
> Sent from the Zend Framework mailing list archive at Nabble.com.
>
--
Matthew Weier O'Phinney
Software Architect | [email protected]
Zend Framework | http://framework.zend.com/