Last active
September 22, 2017 19:50
-
-
Save shouse/06f447884fbc85ec122c to your computer and use it in GitHub Desktop.
Iterate through titanium views and look for class
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 getViewByClass | |
* @summary This will take a class and an optional parent and find children with that class | |
* @param {string} _class Class name | |
* @param {object} _parent Optional Parent View to iterate through | |
* @param {number} _depth Optional depth of recursiveness | |
* @returns {array} Array of views with the class | |
* | |
* @TODO Implement _depth and recursive calls | |
*/ | |
exports.getViewByClass = function(_class, _parent, _depth) { | |
_parent = _parent || $.main; | |
var classArray = []; | |
_.each(_parent.children, function(child){ | |
if (child.className === _class) { | |
classArray.push(child); | |
} | |
}); | |
return classArray; | |
}; |
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 getViewByClass | |
* @summary This will take a class and an optional parent and find children with that class | |
* @param {string} _element Element name | |
* @param {object} _parent Optional Parent View to iterate through | |
* @param {number} _depth Optional depth of recursiveness | |
* @returns {array} Array of views with the class | |
* | |
* @TODO Implement _depth and recursive calls | |
*/ | |
exports.getViewByElement = function(_element, _parent, _depth) { | |
/* DOES NOT WORK AT ALL - NEED TO CHECK OUT THE CHILD PROPERTIES */ | |
_parent = _parent || $.main; | |
var classArray = []; | |
_.each(_parent.children, function(child){ | |
if (child.className === _class) { | |
classArray.push(child); | |
} | |
}); | |
return classArray; | |
}; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
You need to replace
class.push(child);
withclassArray.push(child);
to get it working.Also, the 3rd
@param
should be named_depth
, not_parent
.