I am using the following code which recursively executes function findWpisInZone()
, code works fine, I just wondering if there is any better way to do it in JS,
DomBuilder.prototype = {
domTree: '',
findWpis: function () {
var dataState = dojo.global.xxx.state.data,
scope = this;
for (var zone in dataState) {
for (var wpi in dataState[zone]) {
this.domTree += '<div data-xxx-type="{0}">'.format(zone);
findWpisInZone(dataState[zone][wpi]);
this.domTree += '</div>';
}
}
function findWpisInZone(wpi, type) {
scope.domTree += '<div data-xxx-type="{0}">'.format(wpi.wpi.webpart_cid);
for (var zone in wpi.zones) {
scope.domTree += '<div data-xxx-type="{0}">'.format(zone)
for (var wpiInner in wpi.zones[zone]) {
// recursion search
findWpisInZone(wpi.zones[zone][wpiInner], type);
}
scope.domTree += '</div>';
}
scope.domTree += '</div>';
}
},