# Class: View

## View

#### new View(name, queryopt, optionsopt)

Creates a new view instance.

##### Parameters:

Name | Type | Attributes | Description
--- | --- | --- | ---
`name` | String |  | The name of the view.
`query` | Object | <optional> | The view's query.
`options` | Object | <optional> | An options object.

Source:
  - View.js, line 25

### Methods

- (static) isLinked() → {Boolean}
- (static) link(outputTargetSelector, templateSelector, optionsopt) → {View}
- (static) unlink(outputTargetSelector, templateSelector) → {View}
- _triggerIndexOf()
- addLinkIO()
- addTrigger()
- count() → {Number}
- data() → {Collection}
- data() → {Collection}
- deferEmit()
- distinct(key, queryopt, optionsopt) → {Array}
- drop() → {boolean}
- emit()
- ensureIndex() → {*}
- filter(query, func, optionsopt) → {Array}
- find() → {Array}
- findById() → {Array}
- findOne() → {Object}
- findSub() → {Array}
- findSubOne() → {Object}
- from(source, callbackopt) → {*}
- ignoreTriggers()
- indexOf() → {*}
- insert()
- off()
- on()
- orderBy(valopt) → {*}
- page(valopt) → {*}
- pageFirst() → {*}
- pageLast() → {*}
- pageScan(val) → {*}
- primaryKey() → {String}
- processTrigger()
- queryAdd(obj, overwrite, refreshopt)
- queryData(queryopt, optionsopt, refreshopt) → {*}
- queryOptions(optionsopt, refreshopt) → {*}
- queryRemove(obj, refreshopt)
- rebuildActiveBucket(orderByopt)
- refresh()
- remove()
- removeLinkIO()
- removeTrigger()
- transform(obj) → {*}
- update()
- updateById()
- willTrigger()

#### (static) isLinked() → {Boolean}

Checks if the instance is data-bound to any DOM elements.

Source:
  - AutoBind.js, line 586

##### Returns:

True if linked, false if not.

Type
  Boolean

#### (static) link(outputTargetSelector, templateSelector, optionsopt) → {View}

Data-binds the view data to the elements matched by the passed selector.

##### Parameters:

Name | Type | Attributes | Description
--- | --- | --- | ---
`outputTargetSelector` | String |  | The jQuery element selector to select the element into which the data-bound rendered items will be placed. All existing HTML will be removed from this element.
`templateSelector` | String | Object |  | This can either be a jQuery selector identifying which template element to get the template HTML from that each item in the view's data will use when rendering to the screen, or you can pass an object with a template key containing a string that represents the HTML template such as: { template: ' {{:name}} ' }
`options` | Object | <optional> | An options object.wd

Source:
  - AutoBind.js, line 596
See:
  - unlink

##### Returns:

Type
  View

#### (static) unlink(outputTargetSelector, templateSelector) → {View}

Removes a previously set-up data-binding via the link() method.

##### Parameters:

Name | Type | Description
--- | --- | ---
`outputTargetSelector` | String | The jQuery target selector.
`templateSelector` | String | The jQuery template selector.

Source:
  - AutoBind.js, line 620
See:
  - link

##### Returns:

Type
  View

#### _triggerIndexOf()

Source:
  - View.js, line 871
See:
  - Mixin.Triggers::_triggerIndexOf()

#### addLinkIO()

Source:
  - View.js, line 843
See:
  - Mixin.Triggers::addLinkIO()

#### addTrigger()

Source:
  - View.js, line 822
See:
  - Mixin.Triggers::addTrigger()

#### count() → {Number}

Returns the number of documents currently in the view.

Source:
  - View.js, line 1339

##### Returns:

Type
  Number

#### data() → {Collection}

Returns the non-transformed data the view holds as a collection reference.

Source:
  - View.js, line 1396

##### Returns:

The non-transformed collection reference.

Type
  Collection

#### data() → {Collection}

Gets the module's internal data collection.

Source:
  - View.js, line 514

##### Returns:

Type
  Collection

#### deferEmit()

Emits an event.

Source:
  - View.js, line 794
See:
  - Mixin.Events::deferEmit()

#### distinct(key, queryopt, optionsopt) → {Array}

Find the distinct values for a specified field across a single collection and returns the results in an array.

##### Parameters:

Name | Type | Attributes | Description
--- | --- | --- | ---
`key` | String |  | The field path to return distinct values for e.g. "person.name".
`query` | Object | <optional> | The query to use to filter the documents used to return values from.
`options` | Object | <optional> | The query options to use when running the query.

Source:
  - View.js, line 806

##### Returns:

Type
  Array

#### drop() → {boolean}

Drops a view and all it's stored data from the database.

Source:
  - View.js, line 879

##### Returns:

True on success, false on failure.

Type
  boolean

#### emit()

Emits an event.

Source:
  - View.js, line 786
See:
  - Mixin.Events::emit()

#### ensureIndex() → {*}

Creates an index on the view.

Source:
  - View.js, line 760
See:
  - Collection::ensureIndex()

##### Returns:

Type
  *

#### filter(query, func, optionsopt) → {Array}

Executes a method against each document that matches query and returns an array of documents that may have been modified by the method.

##### Parameters:

Name | Type | Attributes | Description
--- | --- | --- | ---
`query` | Object |  | The query object.
`func` | function |  | The method that each document is passed to. If this method returns false for a particular document it is excluded from the results.
`options` | Object | <optional> | Optional options object.

Source:
  - View.js, line 1387

##### Returns:

Type
  Array

#### find() → {Array}

Queries the view data.

Source:
  - View.js, line 462
See:
  - Collection::find()

##### Returns:

The result of the find query.

Type
  Array

#### findById() → {Array}

Queries the view data by specific id.

Source:
  - View.js, line 480
See:
  - Collection::findById()

##### Returns:

The result of the find query.

Type
  Array

#### findOne() → {Object}

Queries the view data for a single document.

Source:
  - View.js, line 471
See:
  - Collection::findOne()

##### Returns:

The result of the find query.

Type
  Object

#### findSub() → {Array}

Queries the view data in a sub-array.

Source:
  - View.js, line 489
See:
  - Collection::findSub()

##### Returns:

The result of the find query.

Type
  Array

#### findSubOne() → {Object}

Queries the view data in a sub-array and returns first match.

Source:
  - View.js, line 502
See:
  - Collection::findSubOne()

##### Returns:

The result of the find query.

Type
  Object

#### from(source, callbackopt) → {*}

Sets the source from which the view will assemble its data.

##### Parameters:

Name | Type | Attributes | Description
--- | --- | --- | ---
`source` | Collection | View |  | The source to use to assemble view data.
`callback` | function | <optional> | A callback method.

Source:
  - View.js, line 525

##### Returns:

If no argument is passed, returns the current value of from, otherwise returns itself for chaining.

Type
  *

#### ignoreTriggers()

Source:
  - View.js, line 836
See:
  - Mixin.Triggers::ignoreTriggers()

#### indexOf() → {*}

Source:
  - View.js, line 1404
See:
  - Collection.indexOf

##### Returns:

Type
  *

#### insert()

Executes an insert against the view's underlying data-source.

Source:
  - View.js, line 425
See:
  - Collection::insert()

#### off()

Cancels an event listener.

Source:
  - View.js, line 778
See:
  - Mixin.Events::off()

#### on()

/** Listens for an event.

Source:
  - View.js, line 770
See:
  - Mixin.Events::on()

#### orderBy(valopt) → {*}

Gets / sets the orderBy clause in the query options for the view.

##### Parameters:

Name | Type | Attributes | Description
--- | --- | --- | ---
`val` | Object | <optional> | The order object.

Source:
  - View.js, line 1114

##### Returns:

Type
  *

#### page(valopt) → {*}

Gets / sets the page clause in the query options for the view.

##### Parameters:

Name | Type | Attributes | Description
--- | --- | --- | ---
`val` | Number | <optional> | The page number to change to (zero index).

Source:
  - View.js, line 1131

##### Returns:

Type
  *

#### pageFirst() → {*}

Jump to the first page in the data set.

Source:
  - View.js, line 1151

##### Returns:

Type
  *

#### pageLast() → {*}

Jump to the last page in the data set.

Source:
  - View.js, line 1159

##### Returns:

Type
  *

#### pageScan(val) → {*}

Move forward or backwards in the data set pages by passing a positive or negative integer of the number of pages to move.

##### Parameters:

Name | Type | Description
--- | --- | ---
`val` | Number | The number of pages to move.

Source:
  - View.js, line 1172

##### Returns:

Type
  *

#### primaryKey() → {String}

Gets the primary key for this view from the assigned collection.

Source:
  - View.js, line 815
See:
  - Collection::primaryKey()

##### Returns:

Type
  String

#### processTrigger()

Source:
  - View.js, line 864
See:
  - Mixin.Triggers::processTrigger()

#### queryAdd(obj, overwrite, refreshopt)

Add data to the existing query.

##### Parameters:

Name | Type | Attributes | Description
--- | --- | --- | ---
`obj` | Object |  | The data whose keys will be added to the existing query object.
`overwrite` | Boolean |  | Whether or not to overwrite data that already exists in the query object. Defaults to true.
`refresh` | Boolean | <optional> | Whether or not to refresh the view data set once the operation is complete. Defaults to true.

Source:
  - View.js, line 984

#### queryData(queryopt, optionsopt, refreshopt) → {*}

Gets / sets the query object and query options that the view uses to build it's data set. This call modifies both the query and query options at the same time.

##### Parameters:

Name | Type | Attributes | Description
--- | --- | --- | ---
`query` | Object | <optional> | The query to set.
`options` | Boolean | <optional> | The query options object.
`refresh` | Boolean | <optional> | Whether to refresh the view data after this operation. Defaults to true.

Deprecated:
  - Use query(<query>, <options>, <refresh>) instead. Query now supports being presented with multiple different variations of arguments.
Source:
  - View.js, line 937

##### Returns:

Type
  *

#### queryOptions(optionsopt, refreshopt) → {*}

Gets / sets the query options used when applying sorting etc to the view data set.

##### Parameters:

Name | Type | Attributes | Description
--- | --- | --- | ---
`options` | Object | <optional> | An options object.
`refresh` | Boolean | <optional> | Whether to refresh the view data after this operation. Defaults to true.

Source:
  - View.js, line 1200

##### Returns:

Type
  *

#### queryRemove(obj, refreshopt)

Remove data from the existing query.

##### Parameters:

Name | Type | Attributes | Description
--- | --- | --- | ---
`obj` | Object |  | The data whose keys will be removed from the existing query object.
`refresh` | Boolean | <optional> | Whether or not to refresh the view data set once the operation is complete. Defaults to true.

Source:
  - View.js, line 1017

#### rebuildActiveBucket(orderByopt)

Clears the existing active bucket and builds a new one based on the passed orderBy object (if one is passed).

##### Parameters:

Name | Type | Attributes | Description
--- | --- | --- | ---
`orderBy` | Object | <optional> | The orderBy object describing how to order any data.

Source:
  - View.js, line 1228

#### refresh()

Refreshes the view data such as ordering etc.

Source:
  - View.js, line 1250

#### remove()

Executes a remove against the view's underlying data-source.

Source:
  - View.js, line 453
See:
  - Collection::remove()

#### removeLinkIO()

Source:
  - View.js, line 850
See:
  - Mixin.Triggers::removeLinkIO()

#### removeTrigger()

Source:
  - View.js, line 829
See:
  - Mixin.Triggers::removeTrigger()

#### transform(obj) → {*}

Takes the passed data and uses it to set transform methods and globally enable or disable the transform system for the view.

##### Parameters:

Name | Type | Description
--- | --- | ---
`obj` | Object | The new transform system settings "enabled", "dataIn" and "dataOut": { "enabled": true, "dataIn": function (data) { return data; }, "dataOut": function (data) { return data; } }

Source:
  - View.js, line 1360

##### Returns:

Type
  *

#### update()

Executes an update against the view's underlying data-source.

Source:
  - View.js, line 433
See:
  - Collection::update()

#### updateById()

Executes an updateById against the view's underlying data-source.

Source:
  - View.js, line 445
See:
  - Collection::updateById()

#### willTrigger()

Source:
  - View.js, line 857
See:
  - Mixin.Triggers::willTrigger()

### Members

- query

#### query

Gets / sets the query being used to generate the view data. It does not change or modify the view's query options.

Source:
  - View.js, line 1049