Using the Function:: Method for Spry Processing

With Spry 1.6.1, we introduced the idea of using external functions to do Spry processing. Instead of the usual way of:

<div spry:if="'{firstname}' == 'Edward'">

we can externalize the logic like this:


function checkName(rgn, doIt)
     return doIt('{name}') == 'Adobe Studio 8';


<div spry:if="function::checkName">

The 2 parameters passed to the function can be whatever names you wish. The first one names the region being processed, the second is the name of the function used in the expression. Any data reference used in this external function must be wrapped like funcNam('{dataref}')

But even better is the idea that these functions can be used AS data references. This allows you to process these data refs within the function and return that value. This can be helpful in date or currency formatting, for example.

function FormattedPrice(region, lookupFunc)
     return "$" + parseInt(lookupFunc("{price}")).toFixed(2);


<div spry:region="ds1" class="liveSample">
<ul spry:repeatchildren="ds1">
<li>{name} - {function::FormattedPrice}</li>

Copyright © 2008. Adobe Systems Incorporated.
All rights reserved.