Created
August 18, 2014 15:41
-
-
Save dhritzkiv/2fd9165b61e8fc91aa0f to your computer and use it in GitHub Desktop.
RenderCollection fails when called from another RenderCollection (seemingly)
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
| /* The UserOrder View. It calls .renderCollection on a collection that is part of its model. */ | |
| var View = require('ampersand-view'); | |
| var templates = require('../templates'); | |
| var UserOrderProductView = require("./user-order-product"); | |
| module.exports = View.extend({ | |
| template: templates.includes.userOrder, | |
| render: function(opts) { | |
| var self = this; | |
| this.renderWithTemplate(this); | |
| var productsElm = self.getByRole("products"); | |
| self.renderCollection(self.model.products, UserOrderProductView, productsElm, opts); | |
| return this; | |
| } | |
| }) |
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
| /* This works fine. It calls the UserOrder View as a subview. The .renderCollection in UserOrderView works fine here. */ | |
| var PageView = require('ampersand-view'); | |
| var AmpersandModel = require('ampersand-model'); | |
| var templates = require('../templates'); | |
| var UserOrderView = require('../views/user-order'); | |
| module.exports = PageView.extend({ | |
| template: templates.pages.checkoutSummary, | |
| initialize: function() { | |
| //I assign the model here from a global collection .get() call; | |
| }, | |
| render: function() { | |
| var self = this; | |
| this.renderWithTemplate(); | |
| }, | |
| subviews: { | |
| order: { | |
| role: "order", | |
| prepareView: function(el) { | |
| var self = this; | |
| var model = this.model; | |
| var view = new UserOrderView({ | |
| el: el, | |
| model: model, | |
| parent: this | |
| }); | |
| return view; | |
| } | |
| } | |
| } | |
| }) |
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
| var PageView = require('ampersand-view'); | |
| var templates = require('../templates'); | |
| var UserOrderView = require('../views/user-order'); | |
| module.exports = PageView.extend({ | |
| pageTitle: "Orders", | |
| template: templates.pages.userOrders, | |
| initialize: function(spec) { | |
| var self = this; | |
| this.collection = spec.collection;//I pass in the collection of UserOrder Models which are rendered in UserOrder Views (below) | |
| }, | |
| render: function(opts) { | |
| this.renderWithTemplate(this); | |
| var ordersElm = this.getByRole("orders"); | |
| this.renderCollection(this.collection, UserOrderView, ordersElm); | |
| //I render a collection of UserOrder Models using UserOrderView. | |
| //The .renderCollection inside of UserOrderView fails here (Uncaught Exception). If I comment out that method call, everything else renders okay. | |
| return this; | |
| } | |
| }) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment