hashchange / backbone.select Goto Github PK
View Code? Open in Web Editor NEWSelecting Backbone models; handling selections in Backbone collections.
License: MIT License
Selecting Backbone models; handling selections in Backbone collections.
License: MIT License
Lets assume this:
So we will have:
I beliave we should fire deselected event first (and have zero selected models at some point) and then select the target model.
When I was experimenting with substituting lodash for backbone, this mixin stopped working. Looking closer, the extend method in the latest underscore and most lodash versions only copies an objects own properties. Version <=1.6 of underscore will include properties defined on the prototype so the following method was working there:
_.extend( hostObject, new Backbone.Select.One() );
Since I didn't see a need for the instance, I just made the mixins plain objects and passed those to the extend methods like so.
_.extend( hostObject, SelectOneMixin );
I'll attach a PR shortly. Other than that, thanks for this project. It's been very helpful.
Cheers!
If a model in a Collection.Select.Many is selected and then the collection is reset with new models, the collection.selected
property still returns the first model even though it is no longer in the collection. Furthermore, if deselectAll
is called on the collection, the model remains in the collection.selected
property and is not selected.
Here's a fiddle illustrating the problem: https://jsfiddle.net/57pap602/1/.
Hi There,
Thanks for a nice mix in. I've am wondering if it can cover a few usage cases I am not clear about after reading documentation and testing a little bit. Please consider the following cases:
Scenario 1:
A collection where we want to track selected state for a model that has been "starred" and a model that has been "up voted" (tracking two separate selected states for models in the same collection).
Scenario 2:
A model is passed between "collection a" which uses "select one" mix in and "collection b" that uses "select many" mix in. The model had previously been selected in collection a and we want to keep it's selected state until another model is selected or that model is deselected. Additionally, we want to make the model available to be one of the many selected in collection b without affecting it's select one status from "collection a".
Thanks for considering.
Justin
How to use this repo to get current number of items selected in dropdown and disable, say if 20 threshold is exceeded?
i.e Modal defaults to blank then as user clicks will show:
Selected 1 of 20 selected
Selected 2 of 20 selected
Selected 20 of 20 selected etc
one more click:
Cannot exceed 20 and also disables click until unless than threshold
Although not really documented (I had to go to the source code to verify) a Backbone.Collection will let you initialize a collection with an object that may not be an array of models with the {parse:true}
option. Backbone will then call the parse function on the object passed in, which can convert the object passed in to an array of models. However backbone.select requires the 'models' passed in to be an array.
I noticed this in tests where I setup my collections with a json object that mimics my server call and then I pass that to my new collection with {parse: true}
. This worked fine with backbone.picky (since the models weren't passed in to it), however it breaks backbone.select
I am able to work around it since it is in my test code, however it does seem to be an incompatibility with the Backbone API on backbone.select's part.
Hello.
Can you publish this package to npm registry, so that it can be installed directly via npm install
(and used with Browerify for instance).
Thank you.
Can I work with default label using Backbone.Select.One for collection and with custom label using Backbone.Select.Many for single collection?
I tried using backbone.select, but noticed it didn't function properly in my project, so I set up a bare bones example using your "introductory example", but it still doesn't work unfortunately.
I get the following in the console:
"error"
"TypeError: Cannot read property 'id' of undefined
at http://run.jsbin.com/runner:24:58"
which points to the statement console.log( collection.selected.id );
And this console.log( m1.selected );
outputs undefined
as well.
Because it breaks dependencies with webpack and leads to 2 BB versions
I'm using another library Supermodel.js and this provides it's own module that inherits from Backbone.Model. The check for the model type: model instanceof Backbone.Model only checks the parent and not the full hierarchy. I'm wondering if there'd be another way to check the full hierarchy to see if the model descends from Backbone.Model. Another solution would be to make supermodel work as a mixin similarly to backbone.select.
Hi,
I am attempting to use the backbone.select plugin, specifically the select.one mix in. I have followed all guidelines but keep getting an error when I attempt to select a model from the collection:
model = this.collection.get(uid);
this.collection.select(model);
Uncaught TypeError: this.selected.select is not a function
The error references line 69 in the backbone.select amd distribution:
if ( !options._processedBy[this.selected.cid] ) this.selected.select( stripLocalOptions( options ) );
The collection is empty when initialized but that should not make a difference as it has certanly been populated and reset by the time I am calling the method..
Is this a known issue or gotcha?
Thanks,
Justin
A declarative, efficient, and flexible JavaScript library for building user interfaces.
๐ Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. ๐๐๐
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google โค๏ธ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.