![Oracle Drags Its Feet in the JavaScript Trademark Dispute](https://cdn.sanity.io/images/cgdhsj6q/production/919c3b22c24f93884c548d60cbb338e819ff2435-1024x1024.webp?w=400&fit=max&auto=format)
Security News
Oracle Drags Its Feet in the JavaScript Trademark Dispute
Oracle seeks to dismiss fraud claims in the JavaScript trademark dispute, delaying the case and avoiding questions about its right to the name.
knockout-collection
Advanced tools
A knockout observable array as hashmap
var item1 = {
id: ko.observable(1),
label: 'Item 1'
};
var item2 = {
id: ko.observable(2),
label: 'Item 2'
}
var collection = new KnockoutCollection([item1], { key: 'id' });
expect(collection.get(2)).to.be.undefined;
collection.add(item2);
expect(collection.get(2)).to.have.property('label', 'Item 2');
collection.remove(item1);
collection.remove(item2);
expect(collection.toArray()).to.have.length(0);
If you need direct access to the underlying ko.observableArray
you can use collection.items
. Use this only to bind, not to modify.
You can pass an array as items.
new KnockoutCollection(['my', 'array', 'items']);
If you want to manage an ko.observableArray
you can pass it as items
and set the option: reference
:
var items = ko.observableArray([item1, item2]);
var collection = new KnockoutCollection(items, { key: 'id', reference: true });
collection.remove(item1);
// items() will be [item2]
adds an item to the collection which is identified by the value of the (observable-)property with name options.key
.
The item is only added, if it isn't already contained in the collection
removes the item from the collection. If it isnt available in the collection nothing is done
returns the item with the value of the (observable-)property with name options.key
equal to keyValue
.
it will return undefined
if the collection does not contain the item.
checks if the item is contained in the collection.
You can use the length property as you would use it for an array:
var collection = new KnockoutCollection(['i1', 'i2']);
console.log(collection.length === 2); // is true
Removes all items from the collection
FAQs
A knockout observable array as hashmap
The npm package knockout-collection receives a total of 0 weekly downloads. As such, knockout-collection popularity was classified as not popular.
We found that knockout-collection demonstrated a not healthy version release cadence and project activity because the last version was released a year ago. It has 1 open source maintainer collaborating on the project.
Did you know?
Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.
Security News
Oracle seeks to dismiss fraud claims in the JavaScript trademark dispute, delaying the case and avoiding questions about its right to the name.
Security News
The Linux Foundation is warning open source developers that compliance with global sanctions is mandatory, highlighting legal risks and restrictions on contributions.
Security News
Maven Central now validates Sigstore signatures, making it easier for developers to verify the provenance of Java packages.