new Data/BeanCollection()
Base bean collection class. It extends Backbone.Collection.
A bean collection is a collection of beans. To instantiate a bean collection, you need to use Data/DataManager#createBeanCollection.
Example of usage:
The following snippet will create a collection of bean which belongs to the module 'Accounts':
const DataManager = require('data/data-manager');
let accounts = DataManager.createBeanCollection('Accounts');
accounts.add({name: 'account1', industry: 'Banking'});Filtering and searching
The collection's Data/BeanCollection#fetch method supports filter and
search options. For example, to search favorite accounts that have the string
"Acme" in their name:
const DataManager = require('data/data-manager');
let accounts = DataManager.createBeanCollection('Accounts');
accounts.fetch({
    favorites: true,
    query: "Acme"
});Members
- 
    <readonly> favorites :boolean
- 
    
    Flag indicating if a collection contains current user's favorite items. Type:- boolean
 
- 
    fields :Array
- 
    
    Field names. A list of fields that are populated on collection members. This property is used to build the fieldsURL parameter when fetching beans.Type:- Array
 
- 
    filterDef :Array
- 
    
    Filter definition to filter the collection by. Type:- Array
 
- 
    link
- 
    
    Link information. { name: link name, bean: reference to the related bean }
- 
    link :Object
- 
    
    Reference to a relationship. Type:- Object
 
- 
    <readonly> model :Data/Bean
- 
    
    The default model of a bean collection is a Data/Bean. Type:
- 
    <readonly> module :string
- 
    
    The module name. Type:- string
 
- 
    <readonly> myItems :boolean
- 
    
    Flag indicating if a collection contains items assigned to the current user. Type:- boolean
 
- 
    <readonly> offset :number
- 
    
    Current collection offset for pagination. Type:- number
 
- 
    <readonly> query :string
- 
    
    Search query. Type:- string
 
- 
    <readonly> total :number
- 
    
    Readonly property for the total records in server. Use Data/BeanCollection#fetchTotal to get the current total. Type:- number
 
Methods
- 
    <protected> _decrementTotal()
- 
    
    Decrements the collection total. 
- 
    abortFetchRequest()
- 
    
    Aborts the currently active fetch request. 
- 
    add(models, options)
- 
    
    Keeps track of the added models. Parameters:Name Type Description modelsObject | Array.<Object> | Data/Bean | Array.<Data/Bean> The models to add. optionsObject A hash of options. Returns:The added models. 
- 
    clone()
- 
    
    Clones the collection including the Data/BeanCollection#link and all the persistent options. Returns:The new collection with an identical list of models as this one. - Type
- Data/BeanCollection
 
- 
    constructor(models [, options])
- 
    
    Prepares related bean collections and attach collection plugins. Parameters:Name Type Argument Description modelsArray.<Object> | Array.<Data/Bean> Initial array of models. optionsObject <optional> 
 A hash of options. PropertiesName Type Argument Description linkObject <optional> 
 A link specification. 
- 
    dispose()
- 
    
    Disposes this collection. 
- 
    fetch( [options])
- 
    
    Fetches beans. See Data/BeanCollection#paginate for details about pagination options. Only one fetch request can be executed at a time - previous fetch requests will be aborted. Parameters:Name Type Argument Description optionsObject <optional> 
 Fetch options. PropertiesName Type Argument Description relateboolean <optional> 
 trueif relationships should be fetched.falseotherwise.myItemsboolean <optional> 
 trueif only records assigned to the current user should be fetched.falseotherwise.favoritesboolean <optional> 
 trueif favorited records should be fetched.falseotherwise.addboolean <optional> 
 trueif new records should be appended to the collection.falseotherwise.querystring <optional> 
 Search query string. successfunction <optional> 
 The success callback to execute. errorfunction <optional> 
 The error callback to execute. Returns:The created fetch request. - Type
- SUGAR.HttpRequest
 
- 
    fetchTotal( [options])
- 
    
    Fetches the total amount of records on the bean collection, and sets it on the Data/BeanCollection#total property. Returns the total amount of filtered records if a filterDefproperty is set on the collection.Parameters:Name Type Argument Description optionsObject <optional> 
 Fetch total options. PropertiesName Type Argument Description successfunction <optional> 
 Success callback. completefunction <optional> 
 Complete callback. errorfunction <optional> 
 Error callback. Returns:Result of SUGAR.Api#call, or undefinedif Data/BeanCollection#total is notnull.- Type
- SUGAR.HttpRequest | undefined
 
- 
    getDelta()
- 
    
    Gets a hash of unsynced changes operated on the collection. Adds the relationship fields for records to be linked. Returns:A hash representing the unsynced changes. - Type
- Object
 
- 
    getFetchRequest()
- 
    
    Gets the currently active fetch request. Returns:The currently active http fetch request. - Type
- SUGAR.HttpRequest
 
- 
    getModelIndex(model)
- 
    
    Returns the index of the model in this collection. Parameters:Name Type Description modelObject Current model. Returns:The index of the passed modelin this array.- Type
- number
 
- 
    getNext(current, callback)
- 
    
    Returns the next model in a collection, paginating if needed. Parameters:Name Type Description currentObject Current model or id of a model. callbackObject Callback for success call. 
- 
    getOption( [key])
- 
    
    Gets one or all persistent fetch options. Parameters:Name Type Argument Description keystring | Object <optional> 
 The name of the option to retrieve, or nothing to retrieve all options. Returns:A specific option, or the list of options. - Type
- *
 
- 
    getPageNumber( [options])
- 
    
    Gets the current page of collection being displayed depending on the offset. Parameters:Name Type Argument Description optionsObject <optional> 
 Fetch options used when paginating. PropertiesName Type Argument Default Description limitnumber <optional> 
 App.config.maxQueryResult The size of each page. Returns:The current page number. - Type
- number
 
- 
    getPrev(current, callback)
- 
    
    Finds the previous model in a collection and calls a function on it. Parameters:Name Type Description currentObject Current model or id of a model. callbackfunction Callback for success call. 
- 
    hasAtLeast(amount [, options])
- 
    
    A convenience method that checks to see if there are at least the amount of records passed in amount. Also passes to a provided success callback the length of records up toamount, and if there are more records to be fetched (hasMore).Fetches the partial amount of filtered records if a filterDefproperty is set on the collection.Parameters:Name Type Argument Description amountnumber The number of records to check if there are a minimum of. optionsObject <optional> 
 Fetch partial total options. PropertiesName Type Argument Description filterDefObject <optional> 
 Filter definition to be applied. successfunction <optional> 
 Success callback. completefunction <optional> 
 Complete callback. errorfunction <optional> 
 Error callback. Returns:Result of SUGAR.Api#call. - Type
- SUGAR.HttpRequest
 
- 
    hasDelta()
- 
    
    Checks if there is anything in the deltas. Returns:trueif some records are to be created, linked or unlinked to the bean.- Type
- boolean
 
- 
    hasNextModel(current)
- 
    
    Checks whether is there next model in collection. Parameters:Name Type Description currentObject Current model or id of a model. Returns:trueif has next model,falseotherwise.- Type
- boolean
 
- 
    hasPreviousModel(current)
- 
    
    Checks whether is there previous model in this collection. Parameters:Name Type Description currentObject Current model or id of a model. Returns:trueif has previous model,falseotherwise.- Type
- boolean
 
- 
    initialize(models, options)
- 
    
    Sets the given options persistently on the bean collection. They will be used by Data/BeanCollection#fetch. Parameters:Name Type Description modelsArray.<Object> | Array.<Data/Bean> Initial array of models. optionsObject Backbone collection options. 
- 
    paginate( [options])
- 
    
    Paginates a collection. This methods calls Data/BeanCollection#fetch, hence it supports the same options as well as the one described below. Parameters:Name Type Argument Description optionsObject <optional> 
 Fetch options. PropertiesName Type Argument Default Description pagenumber <optional> 
 1 Page index from the current page to paginate to. 
- 
    remove(models, options)
- 
    
    Keeps track of the removed models. Parameters:Name Type Description modelsObject | Array.<Object> | Data/Bean | Array.<Data/Bean> The models to remove. optionsObject A hash of options. Returns:The removed models. 
- 
    reset(models, options)
- 
    
    Keeps track of the unsynced changes on this collection. Parameters:Name Type Description modelsObject | Array.<Object> | Data/Bean | Array.<Data/Bean> The models to reset the collection with. optionsObject A hash of options. Returns:The model(s) you have reset the collection with. 
- 
    resetDelta()
- 
    
    Resets the delta object representing the unsaved collection changes. 
- 
    resetPagination()
- 
    
    Resets pagination properties on this collection to initial values. 
- 
    setOption(key [, val])
- 
    
    Sets the default fetch options (one or many) on the model. Parameters:Name Type Argument Description keystring | Object The name of the attribute, or a hash of attributes. val* <optional> 
 The default value for the keyargument.Returns:This instance. - Type
- Data/BeanCollection
 
- 
    toString()
- 
    
    Returns string representation useful for debugging. Format: coll:[module-name]-[length]orcoll:[related-module-name]/[id]/[module-name]-[length]if it's a collection of related beans.Returns:The string representation of this collection. - Type
- string
 
- 
    unsetOption( [key])
- 
    
    Unsets a default fetch option (or all). Parameters:Name Type Argument Description keystring | Object <optional> 
 The name of the option to unset, or nothing to unset all options. Returns:This instance. - Type
- Data/BeanCollection