04.02.2013 Views

Spry User Guide - Support - Adobe

Spry User Guide - Support - Adobe

Spry User Guide - Support - Adobe

SHOW MORE
SHOW LESS

Create successful ePaper yourself

Turn your PDF publications into a flip-book with our unique Google optimized e-Paper software.

var dsPhotos = new <strong>Spry</strong>.Data.XMLDataSet("/photos.php?galleryid=2000",<br />

"/gallery/photos/photo");<br />

...<br />

// Filter out all rows that don't have a path that begins<br />

// with the letter 's'.<br />

var myFilterFunc = function(dataSet, row, rowNumber)<br />

{<br />

if (row["@path"].search(/^s/) != -1)<br />

return row; // Return the row to keep it in the data set.<br />

return null; // Return null to remove the row from the data set.<br />

}dsPhotos.filter(myFilterFunc); // Filter the rows in the data set.<br />

To get the original data back, call filter() and pass a null argument<br />

dsPhotos.filter(null); // Turn off non-destructive filtering.<br />

Refresh data<br />

Data sets can reload their data at a specified interval expressed in milliseconds. This can be handy when the data at<br />

a given URL changes periodically.<br />

❖ To tell a data set to load at a given interval, pass the optional loadInterval option when calling the XMLDataSet<br />

constructor:<br />

// Load the data every 10 seconds. Turn off the cache to make sure we get it directly from<br />

the server.<br />

var dsPhotos = new <strong>Spry</strong>.Data.XMLDataSet("/photos.php?galleryid=2000",<br />

"/gallery/photos/photo", { useCache: false, loadInterval: 10000 });<br />

You can also turn on this interval loading programatically with the startLoadInterval() method, and stop it with<br />

the stopLoadInterval() method.<br />

dsPhotos.startLoadInterval(10000); // Start loading data every 10 seconds.<br />

...<br />

dsPhotos.stopLoadInterval(); // Turn off interval loading.<br />

Work with observer notifications<br />

SPRY<br />

<strong>User</strong> <strong>Guide</strong><br />

Observer notifications overview<br />

The XML data set supports an observer mechanism that allows an object or callback function to receive event notifications.<br />

Notification Description<br />

onPreLoad The data set is about to send a request for data. If the data set<br />

depends on other data sets, this event notification will not send until<br />

they are all loaded successfully.<br />

onPostLoad The request for data was successful. The data is accessible.<br />

onLoadError An error occurred while requesting the data.<br />

onDataChanged The data in the data set has been modified.<br />

126

Hooray! Your file is uploaded and ready to be published.

Saved successfully!

Ooh no, something went wrong!