Collections
WireBootstrap collections allow an array of objects to be managed using one of the attributes as a key.
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);
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);
To pull an object out of the collection, use the
get
method with the key value....
const mike = col.get("mchermela");
Use the
remove
method with the key to remove an object from the collection....
col.remove("jkratz");
To pull the array out of the collection, use the array method.
...
const users = col.array();
Last modified 2yr ago