Add a new model with a unique GUID, if it doesn't already have its own ID * @param {Model} model - The Backbone Model to save to LocalStorage * @returns {Model} The saved model
(model)
| 62 | * @returns {Model} The saved model |
| 63 | */ |
| 64 | create(model) { |
| 65 | if (!model.id && model.id !== 0) { |
| 66 | model.id = guid(); |
| 67 | model.set(model.idAttribute, model.id); |
| 68 | } |
| 69 | |
| 70 | this._setItem(this._itemName(model.id), this.serializer.serialize(model)); |
| 71 | this.records.push(model.id.toString()); |
| 72 | this.save(); |
| 73 | |
| 74 | return this.find(model); |
| 75 | } |
| 76 | |
| 77 | /** Update an existing model in LocalStorage |
| 78 | * @param {Model} model - The model to update |