Skip to content

Instantly share code, notes, and snippets.

@morewry
Last active December 19, 2015 03:59
Show Gist options
  • Save morewry/5894053 to your computer and use it in GitHub Desktop.
Save morewry/5894053 to your computer and use it in GitHub Desktop.
Backbone & Backbone Layout Manager - search for a nested view, recursive getView
// 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