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. |
Methods
(static) isLinked() → {Boolean}
Checks if the instance is data-bound to any DOM elements.
- Source:
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:
- 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 |
Selector | The jQuery target selector. |
templateSelector |
Selector | The jQuery template selector. |
- Source:
- See:
-
- link
Returns:
- Type
- View
(private) _chainHandler(chainPacket)
The chain reaction handler method for the view.
Parameters:
Name | Type | Description |
---|---|---|
chainPacket |
Object | The chain reaction packet to handle. |
(private) _collectionDropped(collection)
Handles when an underlying collection the view is using as a data
source is dropped.
Parameters:
Name | Type | Description |
---|---|---|
collection |
Collection | The collection that has been dropped. |
(private) _transformSetData()
Updates the public data object to match data from the private data object
by running private data through the dataIn method provided in
the transform() call.
count() → {Number}
Returns the number of documents currently in the view.
Returns:
- Type
- Number
data() → {Collection}
Gets the module's internal data collection.
Returns:
- Type
- Collection
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. |
Returns:
- Type
- Array
drop() → {boolean}
Drops a view and all it's stored data from the database.
Returns:
True on success, false on failure.
- Type
- boolean
emit()
Emits an event.
ensureIndex() → {*}
Creates an index on the view.
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. |
Returns:
- Type
- Array
find() → {Array}
Queries the view data.
Returns:
The result of the find query.
- Type
- Array
findById() → {Array}
Queries the view data by specific id.
Returns:
The result of the find query.
- Type
- Array
from(source) → {*}
Sets the source from which the view will assemble its data.
Parameters:
Name | Type | Description |
---|---|---|
source |
Collection | View | The source to use to assemble view data. |
Returns:
If no argument is passed, returns the current value of from,
otherwise returns itself for chaining.
- Type
- *
insert()
Executes an insert against the view's underlying data-source.
off()
Cancels an event listener.
on()
Listens for an event.
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. |
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). |
Returns:
- Type
- *
pageFirst() → {*}
Jump to the first page in the data set.
Returns:
- Type
- *
pageLast() → {*}
Jump to the last page in the data set.
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. |
Returns:
- Type
- *
primaryKey() → {String}
Gets the primary key for this view from the assigned collection.
Returns:
- Type
- String
privateData() → {Collection}
Returns the non-transformed data the view holds as a collection
reference.
Returns:
The non-transformed collection reference.
- Type
- Collection
publicData()
Returns a data object representing the public data this view
contains. This can change depending on if transforms are being
applied to the view or not.
If no transforms are applied then the public data will be the
same as the private data the view holds. If transforms are
applied then the public data will contain the transformed version
of the private data.
The public data collection is also used by data binding to only
changes to the publicData will show in a data-bound element.
query(queryopt, refreshopt) → {*}
Gets / sets the query being used to generate the view data. It
does not change or modify the view's query options.
Parameters:
Name | Type | Attributes | Description |
---|---|---|---|
query |
Object |
<optional> |
The query to set. |
refresh |
Boolean |
<optional> |
Whether to refresh the view data after this operation. Defaults to true. |
Returns:
- Type
- *
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. |
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. |
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. |
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. |
refresh()
Refreshes the view data such as ordering etc.
remove()
Executes a remove against the view's underlying data-source.
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; } } |
Returns:
- Type
- *
update()
Executes an update against the view's underlying data-source.
updateById()
Executes an updateById against the view's underlying data-source.