Created
April 3, 2012 01:42
-
-
Save jarrodbell/2288665 to your computer and use it in GitHub Desktop.
CommandFusion: JavaScript list population example
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| function populateList (listJoin, elements) { | |
| CF.log("Populating list"); | |
| // Clear the list | |
| CF.listRemove(listJoin); | |
| // Create an array to fill with list contents | |
| var newContents = []; | |
| // Avoid using Array.forEach() method as it uses callbacks to access the data, which means code after the forEach loop will be executed before the loop finishes. | |
| for (var i=0; i<elements.length; i++) { | |
| newContents.push({s1: element.textlabel, s2: element.filename}); | |
| } | |
| // Push the array to the list in a single call | |
| // Much more efficient than many CF.listAdd calls within a loop. | |
| CF.listAdd(listJoin, newContents); | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment