-- lightflowmark <1...@lightflowinterrupted.com> wrote
(on Thursday, 23 April 2009, 03:05 AM -0700):
> Not totally sure what you mean by "$testArr is a single item" - it's an
> array, surely, in the same way that array($testArr) is an array?  It's just
> an assoc. array rather than a simple array (if that's the right term -
> simple array?)

What I mean is that the "items" element of the dojo.data payload is
supposed to be an indexed array of associative arrays. In JS, this is an
array of objects.

Your $testArr is an assoc array -- or object in JS. This is why I
suggested you wrap it in an array when passing it to Zend_Dojo_Data.

> In any event, it's actually worse than that - although Zend_Dojo_Data
> will accept array($testArr) as you've outlined, it is no use for the
> Tree widget.  Each of *children* needs to be a simple array also -
> when you view the JSON string, there are no [square brackets] around
> the items in children, so they are not treated as a JS array and Tree
> fails.

This is because you formed your children incorrectly as well.

Unfortunately, there's not a truly easy way to do this. The format for
such hierarchical stores is a bit different:

    {
        name: "top",
        description: "some description",
        children: [
            { _reference: "someName" }
        ]
    },
    {
        name: "someName",
        description: "some description2",
        children: [
            { _reference: "someDeepName" },
            { _reference: "someOtherDeepName" },
        ]
    },
    {
        name: "someDeepName",
        description: "some deep description2",
    },
    {
        name: "someOtherDeepName",
        description: "some deep description4",
    },

Notice that all items are at the same level, and that the "children"
element of each object is an array of objects referring to other
objects.

The way the PHP array should look is as follows:

    $items = array(
        array(
            'name'        => 'top',
            'description' => 'some description',
            'children'    => array(
                array( '_reference' => 'someName' ),
            ),
        ),
        array(
            'name'        => 'someName',
            'description' => 'some description2',
            'children'    => array(
                array( '_reference' => 'someDeepName' ),
                array( '_reference' => 'someOtherDeepName' ),
            ),
        ),
        array(
            'name'        => 'someDeepName',
            'description' => 'some deep description2',
        ),
        array(
            'name'        => 'someOtherDeepName',
            'description' => 'some deep description4',
        ),
    );

You'll likely need to create some logic to build this out from your data
set.


> I feel there ought to be a way to make Zend_Dojo_Data handle this sensibly,
> but am not sure what it might look like (or, after your comments, if it is
> even desirable).

Hierarchical support for dojo.data structures would be a good addition
to the ZF dojo offerring, definitely; I encourage you to assist in a
proposal for doing so. :)


> Matthew Weier O'Phinney-3 wrote:
> > 
> > 
> > 
> > dojo.data expects a format like the following:
> > 
> >     {
> >         identifier: "name",
> >         items:      []
> >     }
> > 
> > The "items" parameter needs to be an array of items. Each item in that
> > array should be an associative array. In your example below, $testArr is
> > a *single* item to send. You would then provide it to Zend_Dojo_Data as
> > this:
> > 
> >     $data = new Zend_Dojo_Data('id', array($testArr), 'description');

-- 
Matthew Weier O'Phinney
Project Lead            | matt...@zend.com
Zend Framework          | http://framework.zend.com/

Reply via email to