Skip to content

Instantly share code, notes, and snippets.

@edchat
Last active December 28, 2015 22:08
Show Gist options
  • Save edchat/7568957 to your computer and use it in GitHub Desktop.
Save edchat/7568957 to your computer and use it in GitHub Desktop.
Function to get the Parent View from a View Target
getParentFromViewTarget: function (viewTarget) {
// summary:
// A convenience function to get the Parent View for a View Target
//
// viewTarget:
// The view target, like "ParentView1,SubViewA,ChildViewX"
//
// Calls would look like this:
//
// var parentViewOfChildViewX = this.app.getParentFromViewTarget("ParentView1,SubViewA,ChildViewX");
//
var p = this;
var parts = viewTarget.split(",");
if (p && parts.length > 1) {
for (var i = 0; i < parts.length - 1; i++) {
var toId = parts[i];
var v = p.children[p.id + "_" + toId];
if (v) {
p = v;
} else {
console.log("Parent view has not been created yet for " + viewTarget);
return null;
}
}
}
console.log("in getParentFromViewTarget for viewTarget [" + viewTarget + "] parent [" + p.id + "]");
return p;
},
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment