Collections

WireBootstrap collections allow an array of objects to be managed using one of the attributes as a key.

Create a Collection

To create a collection, create a new instance of the wire.Collection class passing in the key field that makes each row unique along with the array of data.

let users = [
    { UserName: "jkratz", FullName: "Jamie Kratz", Active: true },
    { UserName: "pdougherty", FullName: "Pat Dougherty" Active: true },
    { UserName: "mchermela", FullName: "Mike Chermela", Active: false }
];

let col = new wire.Collection("UserName", users);

Add an Object

To add an object, use the set method on the collection. This method will add the object to the collection if it does not already exist. If the object exists, it will be overwritten with the object that is passed into the method.

...

const amy = { UserName: "apeters", FullName: "Amy Peters", Active: true };
    
const mike = col.set(amy);

Retrieve an Object

To pull an object out of the collection, use the get method with the key value.

...

const mike = col.get("mchermela");

Remove an Object

Use the remove method with the key to remove an object from the collection.

...

col.remove("jkratz");

Retrieve the Array

To pull the array out of the collection, use the array method.

...

const users = col.array();

For more on WireBootstrap collections, visit wire.Collection.

Last updated