[Dojo-interest] [data]ItemFileReadStore and items with array

Jared Jurkiewicz jared.jurkiewicz at gmail.com
Mon Mar 22 10:29:31 EDT 2010


Use a 'get' function in your structure (a more powerful version of
formatter).   You can then extract the data from the item however you
like.

-- Jared


On Mon, Mar 22, 2010 at 3:17 AM, Patrick Ruzand <pruzand at gmail.com> wrote:
> Hi Jared,
>
> Thx for your answer.
> In fact, my datastore is connected to a datagrid, and this is the
> datagrid that makes the call to  getValue().
> For the sake of completeness, here's more info about the context. I'm
> using a datagrid like a 'PropertyGrid' to visualize and edit
> properties of JavaScript objects. So my data items are kind of
> PropertyDescriptor, and the issue I have appears when the property
> value is an array. In this case, the grid calls getValue() on my item,
> and therefore returns the first array element as you said.
> Anyway, I will try to see another approach if I can't get around the
> grid getValue() call.
>
> thx,
> Patrick
>> ItemFile*Store supports the concept of multi-valued attributes.
>>
>> getValue() ->  Return a signular value.   For a multi-valued attr,
>> this eturns the first entry.
>>
>> getValues() -> Return an array of values (for a multivalued attr, this
>> returns all of them).
>>
>>
>> For attributes you know are multi-valued, use getValues(), not getValue.
>>
>> -- Jared
>>
>>
>> On Fri, Mar 19, 2010 at 6:06 AM, Patrick Ruzand <pruzand at gmail.com> wrote:
>>> Hi,
>>>
>>> I am facing a behavior I don't understand with ItemFileReadStore.
>>> Assuming my data item is like:
>>>
>>> var data = {
>>>  items: [
>>>    {
>>>      name: 'foo',
>>>      tab: [1,2,3]
>>>    }
>>>  ]
>>> };
>>> store = new dojo.data.ItemFileWriteStore({
>>>                        data: data
>>>                    });
>>>
>>> , calling store.getValue(item,'tab') returns 1, that is the 1st
>>> element of the array.
>>>
>>> When looking at the code, it's quite clear:
>>>
>>>        getValue: function(     /* item */ item,
>>>                                                /* attribute-name-string */ attribute,
>>>                                                /* value? */ defaultValue){
>>>                //      summary:
>>>                //              See dojo.data.api.Read.getValue()
>>>                var values = this.getValues(item, attribute);
>>>                return (values.length > 0)?values[0]:defaultValue; // mixed
>>>        },
>>>
>>> since in my case getValues() returns my array.
>>>
>>> Is there something I am doing wrong here ? Maybe it is related the
>>> hierarchical/reference data format ?
>>> what is the proper way to get the value of the 'tab' attribute as an
>>> array ? (The only workaround I found was
>>> to wrap my array within an array : tab:[[1,2,3]]...)
>>>
>>> thx !
>>> --
>>> Patrick
>>> _______________________________________________
>>> FAQ: http://dojotoolkit.org/support/faq
>>> Book: http://docs.dojocampus.org
>>> Dojo-interest at mail.dojotoolkit.org
>>> http://mail.dojotoolkit.org/mailman/listinfo/dojo-interest
>>>
>> _______________________________________________
>> FAQ: http://dojotoolkit.org/support/faq
>> Book: http://docs.dojocampus.org
>> Dojo-interest at mail.dojotoolkit.org
>> http://mail.dojotoolkit.org/mailman/listinfo/dojo-interest
>>
>
>
>
> --
> --
> Patrick
> _______________________________________________
> FAQ: http://dojotoolkit.org/support/faq
> Book: http://docs.dojocampus.org
> Dojo-interest at mail.dojotoolkit.org
> http://mail.dojotoolkit.org/mailman/listinfo/dojo-interest
>


More information about the Dojo-interest mailing list