I want to use a recursive Model/Collection structure to model a tree. I am struggling to get the circular reference to work with RequireJS. I use the CommonJs syntax rather than AMD. I get the following error:
Uncaught Error: Module name "Models/TestModel" has not been loaded yet for context: _
TestModel
define(function (require) {
var
// Dependencies.
Backbone = require('backbone'),
TestCollection = require('Collections/TestCollection'),
TestModel = Backbone.Model.extend({
initialize: function (model) {
this.Children = new TestCollection(model.Children);
}
});
return TestModel;
});
TestCollection
define(function (require) {
var Backbone = require('backbone'),
TestModel = require('Models/TestModel'),
TestCollection = Backbone.Collection.extend({
model: TestModel
});
return TestCollection;
});
Is this possible with Backbone and RequireJS?