# BaseModel Class

Extends BaseObject
Defined in: `js/model/BaseModel.js:21`
Module: model
Parent Module: StructureJS

Base Model is a design pattern used to transfer data between software application subsystems.

Note: If the data doesn't match the property names you can set the value manually after update super method has been called. Also in the class you inherit BaseModel from you can override the update method to handle the data how you want.

## Index

Show: Inherited Protected Private Deprecated

### Properties

- sjsId

### Methods

- BaseModel constructor
- _setData
- _updateData
- clone
- destroy
- fromJSON
- getQualifiedClassName
- toJSON
- toJSONString
- update

## Properties

### `sjsId` Int public

Inherited from BaseObject: `js/BaseObject.js:27`

The sjsId (StructureJS ID) is a unique identifier automatically assigned to most StructureJS objects upon instantiation.

Default: null

There are no properties that match your current filter settings. You can change your filter settings in the index section on this page. index

## Constructor

### `BaseModel`
(

- `[data]`

)

Defined in `js/model/BaseModel.js:21`

#### Parameters:

- `[data]` Any optional

  Provide a way to update the Base Model upon initialization.

#### Example:

    // Example how to extend the BaseModel class.
    var data = {
            make: 'Tesla',
            model: 'Model S',
            YeAr: 2014,
            feature: {
                abs: true,
                airbags: true
            }
    }
    var carModel = new CarModel(data);

    // Example how to extend the BaseModel class.
    var CarModel = (function () {
        var _super = Extend(CarModel, BaseModel);
        function CarModel(data) {
            _super.call(this);

            // You need to have properties so the data will get assigned.
            // If not the data will not get assigned to the vo.
            this.make = null;
            this.model = null;
            this.year = null;
            this.allWheel = false; // Set a default value.

            // You can assign BaseModel to a property which will
            // automatically created it and pass the data to it.
            this.feature = FeatureModel;

            // If you have an array of data and want them assign to a BaseModel.
            this.feature = [FeatureModel];

            if (data) {
                this.update(data);
            }
        }

        // @overridden BaseModel.update
        CarModel.prototype.update = function (data) {
            _super.prototype.update.call(this, data);

            // If the data doesn't match the property name.
            // You can set the value(s) manually after the update super method has been called.
            this.year = data.YeAr;
        };

        return CarModel;
    })();

## Methods

### `_setData`
(

- `key`
- `data`

)
protected

Defined in `js/model/BaseModel.js:124`

TODO: YUIDoc_comment

#### Parameters:

- `key` Object
- `data` Object

### `_updateData`
(

- `keyValue`
- `data`

)
protected

Defined in `js/model/BaseModel.js:148`

TODO: YUIDoc_comment

#### Parameters:

- `keyValue` Object
- `data` Object

### `clone` () BaseModel public

Defined in `js/model/BaseModel.js:212`

Create a clone/copy of the Base Model.

#### Returns:

BaseModel:

#### Example:

    var clone = carModel.clone();

### `destroy` () Void public

Inherited from BaseObject: `js/BaseObject.js:52`

The purpose of the destroy method is to make an object ready for garbage collection. This should be thought of as a one way function. Once destroy is called no further methods should be called on the object or properties accessed. It is the responsibility of those who implement this function to stop all running Timers, all running Sounds, and take any other steps necessary to make an object eligible for garbage collection.

By default the destroy method will null out all properties of the class automatically. You should call destroy on other objects before calling the super.

#### Returns:

Void:

#### Example:

    ClassName.prototype.destroy = function() {
         this._childInstance.destroy();

         _super.prototype.destroy.call(this);
    }

### `fromJSON`
(

- `json`

)
public

Defined in `js/model/BaseModel.js:196`

Converts the string json data into an Object and calls the update method with the converted Object.

#### Parameters:

- `json` String

#### Example:

     var str = '{"make":"Tesla","model":"Model S","year":2014}'
     var carModel = new CarModel();
     carModel.fromJSON(str);

### `getQualifiedClassName` () String public

Inherited from BaseObject: `js/BaseObject.js:40`

Returns the fully qualified class name of an object.

#### Returns:

String:

Returns the class name.

#### Example:

    instance.getQualifiedClassName();

### `toJSON` () BaseModel public

Defined in `js/model/BaseModel.js:171`

Converts the Base Model data into a JSON object and deletes the sjsId property.

#### Returns:

BaseModel:

#### Example:

    var obj = carModel.toJSON();

### `toJSONString` () String public

Defined in `js/model/BaseModel.js:184`

Converts a Base Model to a JSON string,

#### Returns:

String:

#### Example:

    var str = carModel.toJSONString();

### `update`
(

- `data`

)
public

Defined in `js/model/BaseModel.js:94`

Provide a way to update the Base Model.

#### Parameters:

- `data` Any

#### Example:

    // Example of updating some of the data:
    carModel.update({ year: 2015, allWheel: true});

    // Of course you can also do it the following way:
    carModel.year = 2015;
    carModel.allWheel = false;

There are no methods that match your current filter settings. You can change your filter settings in the index section on this page. index