Following on from the last post, this post is about the Dojo JavaScript framework, sorry guys.
Another snippet of code that might help you dynamically generate multiple widgets (hopefully from widgets that you’ve created) based on feeds or array data or pretty much anything.
It was an absolute nightmare to track down how to do this on the Dojo documentation (Dojo has such terrible documentation, they should spend some time working on it, which is why I’m posting sections that people should find helpful)
If you have a dom element and you’re trying to append a series of n nodes to the dom element, that are all generated from material within a greater array of objects:
this.myArray = [{objtype1},{objtype2},{objtype3}]; //For example if you are creating widgets called 'myWidget', to which you pass the arrayValue dojo.forEach(this.myArray,function(arrayObject){ //In this example I'm populating list elements into a UL with the id 'ulHead' node = document.createElement("li"); dojo.byId('ulHead').appendChild(node); //Remember to use the correct widget syntax when declaring var widget = new myWidget({widgetObject:arrayObject},node); });
I’ve just cross-coded that to a generic example from the actual one I’m using and have substituted a forEach in this section for the for loop I’m currently using, but this should help you on the right track if you’re finding the dojo documentation a bit lacking.
LOOK FORWARD TO MORE OF THESE EXCITING PROGRAMMING BLOG POSTS AS TIME WEARS ON.
Popularity: 4% [?]