i'm using backbone create models , collection in es6 follows
import { model, collection } 'backbone'; class plant extends model { defaults() { return { name: 'not specified', height: 0 } } } class greenhouse extends collection { constructor(options) { super(options); this.model = plant; } } let plant1 = new plant({ name: 'rose' }); let plant2 = new plant({ name: 'daisy' }); let house = new greenhouse([plant1, plant2]); house.each(function(plant) { // plant here });
but inside house.each callback plant object has none of properties should
for example console.log(plant.get('name'))
default value 'not specified'
there's not many working examples of backbone in es6 few exist doesn't i'm doing different those. pointers?
edit:
i've tried non-es6 , same happens
let plant = model.extend({ defaults: { name: "not specified", height: 0 } }); var greenhouse = collection.extend({ model: plant });
your import statement has typo (corrected in later revision) :
import { model, collection } 'backbone';
besides rest of snippets seems work intended.
if not please consider reproducing issue in fiddle.
Comments
Post a Comment