Change schema when creating an instance?

138 views Asked by At

Lets say I have the following model as my base for the Form I'm making:

var SomeModel = Backbone.Model.extend({ 
  schema: { --some default things--,
    fieldToChange: {type='Select', options=['Default']},
    fieldToChange2: {type='Select', options=['Default']}
  }
});

Now I want to create a new SomeModel with different options on creation:

var formModel = new SomeModel({
  //Here's where I don't know how to set just the options of fieldToChange
  schema.fieldToChange.options = [A, Computed, Array, Of, Options],
  schema.fieldToChange2.options = [A, Computed, Array, Of, Options, 2]
});
var myForm = new Form({ el: $('#elID'), model: formModel};

Can I update the model's schema on creation similarly to this? What would be the way to make this work appropriately?

1

There are 1 answers

1
evilcelery On BEST ANSWER

Yes, you can make the schema property a function which returns the schema object. That way you can customise the schema for each model however you like.