Permalink
Browse files

fixed issue with array rendering

  • Loading branch information...
1 parent b2c2f5d commit 93c3b143441d9c5abb02fd74951ca7093bbcf194 @tbranyen committed Jun 17, 2012
Showing with 19 additions and 19 deletions.
  1. +15 −16 backbone.layoutmanager.js
  2. +1 −1 dist/backbone.layoutmanager.min.js
  3. +3 −2 examples/append.html
View
@@ -30,26 +30,27 @@ var LayoutManager = Backbone.View.extend({
return manage(this).render();
};
- // Ensure the View is setup correctly
+ // Ensure the View is setup correctly.
LayoutManager.setupView(this, options);
- // Set the prefix for a layout
+ // Set the prefix for a layout.
if (options.paths) {
this._prefix = options.paths.layout || "";
}
- // Have Backbone set up the rest of this View
+ // Have Backbone set up the rest of this View.
Backbone.View.call(this, options);
},
// Shorthand to root.view function with append flag.
- insertView: function(partial, view) {
+ insertView: function(selector, view) {
if (view) {
- return this.setView(partial, view, true);
+ return this.setView(selector, view, true);
}
- // Omitting a partial will place the View directly into the parent.
- return this.setView(partial, true);
+
+ // Omitting a selector will place the View directly into the parent.
+ return this.setView(selector, true);
},
// Works like insertView, except allows you to bulk insert via setViews.
@@ -108,12 +109,6 @@ var LayoutManager = Backbone.View.extend({
// Instance overrides take precedence, fallback to prototype options.
options = view._options();
- // Ensure render is set correctly.
- //if (options.render !== LayoutManager.prototype.options.render) {
- // view.render = options.render;
- // options.render = LayoutManager.prototype.options.render;
- //}
-
// Set up the View.
LayoutManager.setupView(view, options);
@@ -184,7 +179,7 @@ var LayoutManager = Backbone.View.extend({
// Ensure this.views[name] is an array.
partials = this.views[name] = [this.views[name]];
}
-
+
partials.push(view);
return view;
@@ -201,7 +196,7 @@ var LayoutManager = Backbone.View.extend({
// If the view is an array put all views into insert mode
if (_.isArray(view)) {
return _.each(view, function(view) {
- this.setView(name, view, true);
+ this.insertView(name, view);
}, this);
}
@@ -238,8 +233,12 @@ var LayoutManager = Backbone.View.extend({
// For every view in the array, remove the View and it's children.
_.each(_.clone(view), function(subView, i) {
- if (!subView.keep && (subView.options && !subView.options.keep)) {
+ // Ensure keep: true is set for any View that has already rendered.
+ if (subView.__manager__.hasRendered && !subView.keep &&
+ (subView.options && !subView.options.keep)) {
+
subView.remove();
+
// Remove from the array.
view.splice(i, 1);
}
Oops, something went wrong.
View
@@ -30,7 +30,8 @@
<script>
// Create a Content view to be used with the Layout below.
var Content = Backbone.View.extend({
- template: "#content"
+ template: "#content",
+ keep: true
});
// Create a new Layout with a sub view for content.
@@ -41,7 +42,7 @@
// Layout's <p></p>.
views: {
// Appending a new content view using the array syntax
- p: [ new Content() ]
+ p: new Content()
}
});

0 comments on commit 93c3b14

Please sign in to comment.