PDA

View Full Version : passing objects in xtemplate functions



abhi.srinu
5 Jun 2013, 9:40 PM
Hi,

I have built a dataview with a tpl in which i have a button(add to cart) and i want to pass the object so that i can update the store directly
Looks something like this


<tpl for=".">
<div class="thumb-wrap">
<div class="thumb">

<img src='resources/images/{raw.RowNum}.png' alt='{raw.RowNum}'/>

</div>

<br><br><br><br>
<span>{raw.Name}</span>
<br><br>
<input type='button' class='cart-button1' value='Add To Cart' onclick='addToCart({raw})'/>
</div>
</tpl>


But when i render the button changes as:


<input type="button" class="cart-button1" value="Add To Cart" onclick="addToCart([object Object])">

Can any one tell me how do i pass objects to functions from a extjs template?

Thanks in advance,
Abhi.

slemmon
7 Jun 2013, 10:53 AM
See if adding the 'values' variable from XTemplate is what you're looking for:

addToCart({[Ext.encode(values)]})

abhi.srinu
11 Jun 2013, 11:16 PM
:-?
If using Ext.encode(object) and pass it as a string and then use Ext.decode in the function is what you are saying yes it works.

But for the time being I changed it as below


<input type="button" class='cart-button1' value="Add to Cart" onclick="addToCart('{Id}')">
and the function as


function addToCart(itemid)
{


var item=Ext.StoreManager.map.CatServicesStore.findRecord('Id',itemid);
//and do operations on the item

}


So what would you think is better?