MVC.Model

Model represent a data record.

parents: Base

defined in: model.js

Class

Attributes

  • clientId {Function} Generated client id.
  • idAttribute {String} Attribute name used to store id from server.
  • parse {function} parse json from server to get attr/value pairs.
  • sync {Function} Sync model data with server.
  • url {Function} Called to get url for delete/edit/new current model.
  • urlRoot {String} If current model does not belong to any collection.

Methods

  • addToCollection (c) Add current model instance to a specified collection.
  • destroy (opts) destroy this model and sync with server.
  • getId () Get current model 's id.
  • isModified () whether has been modified since last save.
  • isNew () whether it is newly created.
  • load (opts) Load model data from server.
  • removeFromCollection (c) Remove current model instance from a specified collection.
  • save (opts) Save current model 's data to server using sync.
  • setId (id) Set current model 's id.
  • toJSON () Get json representation for current model.

Class Detail

  • MVC.Model ()
    Model represent a data record.

Attributes Detail

  • clientId {Function} Generated client id. Default call S.guid()
  • idAttribute {String} Attribute name used to store id from server. Default: "id".
  • parse {function} parse json from server to get attr/value pairs. Default to return raw data from server.
  • sync {Function} Sync model data with server. Default to call MVC.sync
  • url {Function} Called to get url for delete/edit/new current model. Default: collection.url+"/"+mode.id
  • urlRoot {String} If current model does not belong to any collection. Use this attribute value as collection.url in MVC.Model#url

Methods Detail

  • addToCollection (c) view source
    Add current model instance to a specified collection.
    Parameters
  • destroy (opts) view source
    destroy this model and sync with server.
    Parameters
    • [ opts ] {Object} destroy config.
    •   opts.success {Function} callback when action is done successfully.
    •   opts.error {Function} callback when error occurs at action.
    •   opts.complete {Function} callback when action is complete.
  • getId () view source
    Get current model 's id.
  • isModified () view source
    whether has been modified since last save.
    Returns
    • {Boolean}
  • isNew () view source
    whether it is newly created.
    Returns
    • {Boolean}
  • load (opts) view source
    Load model data from server.
    Parameters
    •   opts {Object} Load config.
    •   opts.success {Function} callback when action is done successfully.
    •   opts.error {Function} callback when error occurs at action.
    •   opts.complete {Function} callback when action is complete.
  • removeFromCollection (c) view source
    Remove current model instance from a specified collection.
    Parameters
  • save (opts) view source
    Save current model 's data to server using sync.
    Parameters
    •   opts {Object} Save config.
    •   opts.success {Function} callback when action is done successfully.
    •   opts.error {Function} callback when error occurs at action.
    •   opts.complete {Function} callback when action is complete.
  • setId (id) view source
    Set current model 's id.
    Parameters
    •   id
  • toJSON () view source
    Get json representation for current model.
    Returns
    • {Object}
blog comments powered by Disqus
Top