I've got it working now, but have a question about the "item must contain a column matching the currently set identifier". It doesn't matter what I use as my identifier value, as long as it's one of the keys in my associate array? Or is this to be thought of more like a primary key in the data set? Sorry - I'm simultaneously learning Dojo at the same time learning the Dojo View Helpers.
Regards
----
Jeremy Brown
Senior Web Developer
Spear One
972.661.6038
www.spearone.com
-----Original Message-----
From: Matthew Weier O'Phinney [mailto:matthew@zend.com]
Sent: Monday, August 25, 2008 2:05 PM
To: fw-mvc@lists.zend.com
Subject: Re: [fw-mvc] How to correctly use Zend_Dojo_Data
-- Jeremy Brown <jbrown@spearone.com> wrote
(on Monday, 25 August 2008, 11:35 AM -0700):
> Does anyone have a working example of using Zend_Dojo_Data? I've been over the
> code in the actual component as well as everything I can find online, mailing
> list archives, etc and I clearly am not understanding how to use it.
>
> Trying various instantiations, I keep toggling between receiving the errors of
> "Only arrays and objects may be attached", "Item must contain a column matching
> the currently set identifier" and "Overwriting items using addItem() is not
> allowed". Clearly my understanding of how to use this module is not accurate.
>
> I am attempting to pass in an array, but am not certain what the structure of
> it should be.
When passing an array, it needs to be an array of _associative_ arrays.
That's where the "item must contain a column matching the currently set
identifier" exception comes in -- if you don't use associative arrays,
then it won't work for dojo.data.
For objects, we either call the object's toArray() method or cast it to
an array using get_object_vars() -- so these should work fine.
As an example of something that would work:
$items = array(
array('name' => 'foo', 'title' => 'Foo'),
array('name' => 'bar', 'title' => 'Bar'),
azray('name' => 'baz', 'title' => 'Baz'),
);
$data = new Zend_Dojo_Data('name', $items);
echo $data->toJson();
--
Matthew Weier O'Phinney
Software Architect | matthew@zend.com
Zend Framework | http://framework.zend.com/
没有评论:
发表评论