MVC.Collection

Collection. A list of model.

parents: Base

defined in: collection.js

Class

Attributes

  • comparator {Function} Comparator function for index getter when adding model.
  • model {MVC.Model} Model constructor with in current collection.
  • models {MVC.Model[]} Model list.
  • parse {Function} Get structured data from raw data returned from server.
  • sync {Function} Sync function to sync data with server.
  • url {String|Function} Get url for sending data to server.

Methods

  • add (model, opts) Add a model to current collection.
  • at (i) Get model at specified index.
  • create (model, opts) Add a model to current collection by provide json data.
  • getByCid (cid) Get model instance by client id.
  • getById (id) Get model instance by id.
  • load (opts) Initialize model list by loading data using sync mechanism.
  • remove (model, opts) Remove an existing model from current collection.
  • sort () Sort model list according MVC.Collection#comparator.
  • toJSON () Get json representation of this collection.

Class Detail

  • MVC.Collection ()
    Collection. A list of model.

Attributes Detail

  • comparator {Function} Comparator function for index getter when adding model. default to append to last of current model list.
  • model {MVC.Model} Model constructor with in current collection.
  • models {MVC.Model[]} Model list.
  • parse {Function} Get structured data from raw data returned from server. default to return raw data from server.
  • sync {Function} Sync function to sync data with server. Default to call MVC.sync
  • url {String|Function} Get url for sending data to server.

Methods Detail

  • add (model, opts) view source
    Add a model to current collection.
    Parameters
    •   model {Object|MVC.Model} Model or json data to be added.
    • [ opts ] {object} Add config
    •   opts.silent {Function} Whether to fire add event.
  • at (i) view source
    Get model at specified index.
    Parameters
    •   i {Number} Specified index.
  • create (model, opts) view source
    Add a model to current collection by provide json data.
    Parameters
    •   model {Object} Json data represent model data.
    •   opts {object} Create config.
    •   opts.success {Function} Callback when create is successful.
    •   opts.error {Function} Callback when error occurs on creating.
    •   opts.complete {Function} Callback when create is complete.
    •   opts.silent {Function} Whether to fire add event.
  • getByCid (cid) view source
    Get model instance by client id.
    Parameters
    •   cid {String} Client id auto generated by model.
  • getById (id) view source
    Get model instance by id.
    Parameters
    •   id {String}
  • load (opts) view source
    Initialize model list by loading data using sync mechanism.
    Parameters
    •   opts {object} Load config.
    •   opts.success {Function} Callback when load is successful.
    •   opts.error {Function} Callback when error occurs on loading.
    •   opts.complete {Function} Callback when load is complete.
  • remove (model, opts) view source
    Remove an existing model from current collection.
    Parameters
    •   model {MVC.Model} Model to be removed.
    • [ opts ] {object} Remove config.
    •   opts.silent {Function} Whether to fire remove event.
  • sort () view source
    Sort model list according MVC.Collection#comparator.
  • toJSON () view source
    Get json representation of this collection.
    Returns
    • Object[]
blog comments powered by Disqus
Top