Research
Security News
Malicious npm Packages Inject SSH Backdoors via Typosquatted Libraries
Socket’s threat research team has detected six malicious npm packages typosquatting popular libraries to insert SSH backdoors.
bb-collection-view
Advanced tools
Easily render backbone.js collections with support for automatic selection of models in response to clicks, reordering models via drag and drop, and more.
For demos see the Backbone.CollectionView home page.
Depends on jQuery and jQueryUI for event handling and sorting, respectively.
var myCollectionView = new Backbone.CollectionView( {
el : $( "#listForCollection" ), // must be a 'ul' (i.e. unordered list) or 'table' element
modelView : EmployeeView, // a View class to be used for rendering each model in the collection
collection : employeeCollection
} );
myCollectionView.render();
myCollectionView.setSelectedModel( employeeCollection.first() );
el
: A <ul>
or <table>
element into which your collection will be rendered. If you supply a <table>
element, your modelView must have an element of type of <tr>
.collection
: The collection of models to be rendered.modelView
: A view constructor that will be used to create the views for each individual model.selectable
: (default: true) Determines whether models in the CollectionView are selectable.reuseModelViews
: (default: true) When true
, modelViews are reused instead of being re-created from scratch when the CollectionView is re-rendered.detachedRendering
: (default: false) When true
, all the modelViews are rendered before being added to the DOM to improve performance. If your modelView rendering relies on its location in the DOM (for sizing or other reasons), use the default value of false
.sortable
: (default: false) Determines if models can be rearranged by dragging and dropping.sortableOptions
: Options passed through to the created jQueryUI sortable. Only applies if sortable
.emptyListCaption
: A string (or a function returning a string) to be shown when the list is empty.The following options apply when selectable
option is set:
clickToSelect
: (default: true) Determines whether mouse clicks should automatically select models as would be appropriate in a standard HTML mutli-SELECT element.processKeyEvents
: (default: true) Determines if the collection view should respond to arrow key events as would be appropriate in a standard HTML multi-SELECT element.selectMultiple
: (default: false) Determines if multiple models can be selected at once.clickToToggle
: (default: false) Determines if clicking a model view should toggle its selected / unselected state. Only applies if selectMultiple
is set.The following options expect a filter function that takes a single parameter, the model in question, and returns true
or false
. They are all optional, defaulting to passing all models.
visibleModelsFilter
: Determines which models are visible.selectableModelsFilter
: In a selectable CollectionView, determines which models are selectable.sortableModelsFilter
: In a sortable CollectionView, determines which models are sortable.el
. The CollectionView is automatically re-rendered if necessary.The getSelectedModel(s)
and setSelectedModel(s)
methods are used to get or set the currently selected models. The methods are able to reference models in a variety of ways using the by
option:
// Returns an array of the selected models
myCollectionView.getSelectedModels();
// Returns an array of the ids of the selected models
myCollectionView.getSelectedModels( { by : "id" } );
// Select model id 2 and model id 4
myCollectionView.setSelectedModels( [ 2, 4 ], { by : "id" } );
// Select the model with cid equal to "c21"
myCollectionView.setSelectedModel( "c21", { by : "cid" } );
// Returns the view object that represents the selected model
myCollectionView.getSelectedModel( { by : "view" } );
As shown in the examples, the plural versions of the methods expect / return an array of "model references", whereas the singular versions expect / return just a single "model reference".
There are four valid values for by
option which determine the type of "model reference" used.
"id"
: The id
of the model."cid"
: The cid
of the model."offset"
: The zero-based index of the model in the collection, only counting visible models."view"
: The view that was created to represent the model when the CollectionView was rendered.If no by
option is provided the model object itself is expected / returned.
Additionally, the setSelectedModel(s)
function accepts one additional option, silent
, which, when true, will prevent the selectionChanged
event from being fired.
##Events Fired
CollectionViews trigger
the following events on themselves. If Backbone.Courier
is available, these events are also "spawned".
setSelectedModel(s)
.selectionChanged
is fired. In addition, it is fired after rendering and sorting.In addition, sortable CollectionViews fire these events:
##Styling
How you style the collection view is up to you.
The ul
or table
element that is used as the collection view's element will be given the collection-list
class. Generally you will want to eliminate bullets, etc., from your collection view list elements, which you can do with these "base" styles:
ul.collection-list {
margin: 0;
padding: 0;
list-style-type: none;
outline: none;
cursor: pointer;
}
When a model is selected, its view's li
or tr
element will be given the selected
class.
You can style the caption created by the emptyListCaption
option with the var.empty-list-caption
selector. These styles will center the empty list caption text near the top of the collection view.
var.empty-list-caption {
color: #A0A0A0;
padding: 30px;
display: block;
text-align: center;
font-style: normal;
line-height: 1.45;
}
(Both of the above css fragments are included in base.css
, which will be included automatically in your css bundles if you are using parcelify or cartero.)
See the the Backbone.CollectionView home page for styling examples.
See the the Backbone.CollectionView home page for styling examples.
##Dependencies
##License MIT
FAQs
Easily render backbone.js collections with support for automatic selection of models in response to clicks, reordering models via drag and drop, and more.
The npm package bb-collection-view receives a total of 1,411 weekly downloads. As such, bb-collection-view popularity was classified as popular.
We found that bb-collection-view demonstrated a not healthy version release cadence and project activity because the last version was released a year ago. It has 2 open source maintainers 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.
Research
Security News
Socket’s threat research team has detected six malicious npm packages typosquatting popular libraries to insert SSH backdoors.
Security News
MITRE's 2024 CWE Top 25 highlights critical software vulnerabilities like XSS, SQL Injection, and CSRF, reflecting shifts due to a refined ranking methodology.
Security News
In this segment of the Risky Business podcast, Feross Aboukhadijeh and Patrick Gray discuss the challenges of tracking malware discovered in open source softare.