Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

throw exception if container selector does not select any elements.

proposed solution to  issue #51
  • Loading branch information...
commit 3869cb49ebd72aaa83c81afd653c048913ba8592 1 parent f72f4b7
@patmoore authored
Showing with 17 additions and 10 deletions.
  1. +17 −10 jquery.views.js
View
27 jquery.views.js
@@ -756,17 +756,24 @@ $.extend({
template = template && (templates[ template ] || (template.markup ? template : $.templates( template )));
context = context || parentView.ctx;
context.link = TRUE;
- container = $( container )
- // .unbind( "change" ) // TODO complete this, by calling unlink? - TODO/BUG. Consider both top-level and template-driven linking
- .bind( "change", dataToElem );
-
- if ( template ) {
- // TODO/BUG Currently this will re-render if called a second time, and will leave stale views under the parentView.views.
- // So TODO: make it smart about when to render and when to link on already rendered content
- container.empty().append( template.render( data, context, parentView )); // Supply non-jQuery version of this...
- // Using append, rather than html, as workaround for issues in IE compat mode. (Using innerHTML leads to initial comments being stripped)
+ var jqueryContainer = $( container );
+ if ( jqueryContainer.length > 0) {
+ jqueryContainer = jqueryContainer
+ // .unbind( "change" ) // TODO complete this, by calling unlink? - TODO/BUG. Consider both top-level and template-driven linking
+ .bind( "change", dataToElem );
+
+ if ( template ) {
+ // TODO/BUG Currently this will re-render if called a second time, and will leave stale views under the parentView.views.
+ // So TODO: make it smart about when to render and when to link on already rendered content
+ jqueryContainer.empty().append( template.render( data, context, parentView )); // Supply non-jQuery version of this...
+ // Using append, rather than html, as workaround for issues in IE compat mode. (Using innerHTML leads to initial comments being stripped)
+ }
+ linkViews( jqueryContainer[0], parentView, undefined, undefined, data, context );
+ } else if (typeof(container)=="string") {
+ throw container +": does not select a DOM element. Template has no place to be inserted.";
+ } else {
+ throw "No DOM element selected. Template has no place to be inserted.";
}
- linkViews( container[0], parentView, undefined, undefined, data, context );
},
unlink: function( container ) {
Please sign in to comment.
Something went wrong with that request. Please try again.