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: 5% [?]
If you're getting an error along the lines of:
Error: You cannot use the Render object without specifying where you want to render it' when calling method
You need to fix the declaration in the widget you're creating, as you've missed something really simple.
Copy the constructor from a pre-existing widget to make sure you haven't missed anything.
Also, make sure you're specifying a valid ID within the DOM.
This just cost me an hour of my day, so I hope this saves you some time.
Popularity: 4% [?]