Last active
December 19, 2015 03:59
-
-
Save morewry/5894053 to your computer and use it in GitHub Desktop.
Backbone & Backbone Layout Manager - search for a nested view, recursive getView
This file contains 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
// Pass in a starting view and match comparison | |
function findView ( startView, searchFn ) { | |
var resultView, | |
viewSearch = function ( curView ) { | |
curView.getView( function ( nestedView ) { | |
if ( searchFn( nestedView ) ) { | |
resultView = nestedView; | |
} | |
else { | |
viewSearch( nestedView ); | |
} | |
}); | |
}; | |
viewSearch( startView ); | |
return resultView; | |
} | |
// Example Use | |
var soughtView = findView(app.useLayout(), function(v) { | |
return (v.options.template == "whatever"); | |
}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment