On Wed, Apr 15, 2009 at 1:50 AM, Dhana <sldh...@gmail.com> wrote:

>
> I am using the jQuery Data method to store data for dynamically
> created elements.  Everything works fine until I try to update the
> value of an attribute.
> This is how I first create the element.
>
>
> $j.data(item, 'attributes', {
>                Name: name,
>                UOM: uom,
>                WarehouseKey: orderItem.WarehouseKey,
>                OriginalPrice: orderItem.OriginalPrice,
>                ReqDate: dsOrder.cleanupResults(orderItem.ReqDate),
>                WarehouseItemKey: orderItem.WarehouseItemKey,
>                AvailableQty: orderItem.AvailableQty,
>                BOQty: orderItem.BOQty,
>                Notes: dsOrder.cleanupResults(orderItem.Notes),
>                Cost: orderItem.Cost,
>                GP: dsOrder.cleanupResults(orderItem.GP),
>                Description: dsOrder.cleanupResults
> (orderItem.description)
>            });
>
> At a later point based on a user's interaction, the required date,
> note, and warehouse key gets updated.
>
> This is the first way I tried updating it, it doesn't store the value.
> $j(item, 'attributes.ReqDate', $j('#section_item #requiredDate').attr
> ('value'));


This doesn't work because the text after the dot (.) is the namespace of the
data attribute.


>
> Then I tried it like this
> $j.data(item, 'attributes', {
>                'WarehouseKey': $j('#<%=ItemWarehouseList.ClientId
> %>').val()
> });
>
> This overwrited all the other data stored in 'attributes'.  Only
> WarehouseKey is then saved.
>
> Is there a way to change just one value without affecting the rest of
> the data?


Grab the hash, modify the value, then put it back:

var attr = $j.data(item, 'attributes');
attr.WarehouseKey = $j('#<%=ItemWarehouseList.ClientId%>').val();
$j.data(item, 'attributes', attr);

- Richard

Reply via email to