javascript - Backbone-Relational with Marionette Require.js and SubModelTypes -
javascript - Backbone-Relational with Marionette Require.js and SubModelTypes -
i'm having slight problem backbone-relational when seek create sub models within marionette module. next backbone-relational documentation have:
mammal = backbone.relationalmodel.extend({ submodeltypes: { 'primate': 'primate', 'carnivore': 'carnivore' } }); primate = mammal.extend(); carnivore = mammal.extend(); mammalcollection = backbone.collection.extend({ model: mammal }); // create collection contains 'primate' , 'carnivore'. var mammals = new mammalcollection([ { id: 3, species: 'chimp', type: 'primate' }, { id: 5, species: 'panther', type: 'carnivore' } ]); var chimp = mammals.get( 3 ); alert( 'chimp mammal? ' + ( chimp instanceof mammal ) + '\n' + 'chimp carnivore? ' + ( chimp instanceof carnivore ) + '\n' + 'chimp primate? ' + ( chimp instanceof primate ) ); this works fine in jsfiddle on end. chimp instance of mammal , primate. problem starts when code gets run within marionette module so:
define( [ "app", "backbone-relational", ], function(managerapp){ managerapp.module("entities", function (entities, managerapp, backbone, marionette, $, _) { var mammal = backbone.relationalmodel.extend({ submodeltypes: { 'primate': 'primate', 'carnivore': 'carnivore' } }); var primate = mammal.extend(); var carnivore = mammal.extend(); var mammalcollection = backbone.collection.extend({ model: mammal }); // create collection contains 'primate' , 'carnivore'. var mammals = new mammalcollection([ { id: 3, species: 'chimp', type: 'primate' }, { id: 5, species: 'panther', type: 'carnivore' } ]); var chimp = mammals.get( 3 ); alert( 'chimp animal? ' + ( chimp instanceof mammal ) + '\n' + 'chimp carnivore? ' + ( chimp instanceof carnivore ) + '\n' + 'chimp primate? ' + ( chimp instanceof primate ) ); }); }) in case, i'm getting true chimp instanceof mammal, false primate , carnivore. realize models should attached entities did not work either , wanted test simplest scenario possible.
why proper submodels not created ?
javascript backbone.js marionette backbone-relational
Comments
Post a Comment