This repository has been archived by the owner on Nov 27, 2018. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 9
Creating a data store
Jason Mulligan edited this page Dec 26, 2012
·
14 revisions
Data stores act as a powerful NoSQL document storage system, with the ability to create cached views
based on sorting one or more fields.
var app = $.data({id: "app"}, null, {key: "name"});
If the Objects in the Array do not have a property matching app.data.key
the Array index value will be used.
// Discarding observer events to minimize latency
$.discard(true);
// Batching in records
app.data.batch("set", recordsArray);
// Enabling observer events for GUI
$.discard(false);
Getting a record can be achieved by passing the data.key
value, or the Array index.
var record = app.data.get("abc-123");
Getting a record set requires passing a second parameter, the number of records to retrieve from the index for the first parameter.
// 5 records (e.g. pagination)
var records = app.data.get(0, 5);
Updating a record will erase views
.
// Record scope
record.set("someProperty", value);
// Data store scope
app.data.set("abc-123", {"someProperty": value});
Deleting a record will remove the record(s) from the data store, erase views
and reindex the records.
// Record scope
record.del();
// Data store scope
app.data.del("abc-123");
Clearing a data store will clear data.records
, data.views
and reset data.total
.
// Resetting the store
app.data.clear();
// Soft reset, leaves RESTful properties as is
app.data.clear(true);