BB: Clone the model attributes in order to fire events

If you don't then no events as just plain object

by kyllle

JavaScript

// Example snippet

// https://stevenschobert.com/writings/arrays-and-objects-in-backbone-models
onAddContact: function() {
    console.log('onAddContact');

    // Loop through inputs
    var inputs = this.$el.find('.js-input-field'),
        newContact = {},
        contacts = _.clone(this.model.get('contacts'));

    inputs.each(function(index, element) {
        // Need to get the clearingFirmId in here
        return newContact[element.name] = element.value;
    });

    newContact["clearingFirmId"] = this.options.id;

    contacts.push(newContact);

    // Now you can set the cloned attributes
    this.model.set({
        contacts: contacts
    });
}