Comments (2)
@signmeuptwice I am sorry you are having hard time with the documentation. Definitely going to improve the corresponding sections.
So the problem here is related to the as
property. It takes place when you are working with non primitive options as with the [ {label:'2000', value:2000 }, {label:'2001', value:2001 },etc...]
in your example. The as
property is expected to be an array of exactly 3 strings (paths): [ label, value, index ]
. Where:
- label is the path to the property of your option object i.e
{label:'2000', value:2000}
which should be used as a display value and also in filtering. It also is the property to which the query will be set when creating new option in tagging mode. - value path is to the property that should be set as model value when an option is selected; if the path is an empty string, the whole object will be assigned to the model.
- index path is very important. It should point to a unique primitive value for each option and is applied as
:key
in the internalv-for
of the options list. It is also used when comparing two options objects e.g. for detecting if an option is selected or not. Therefore it cannot be some random generated value and is important for the end user to have control over it. Usually you would pass a path that points to the option's id.
Some possible values would be: :as="['label', 'value', 'id']"
, :as="['label', '', 'id']"
.
As this is quite verbose it is supported to pass these paths as a simple :
separated string: as="label:value:id"
and as="label::id"
respectively.
That said, for your particular example the :as="'label::value'"
is correct and should be working just fine. But if you get duplicate key
error it means you have two or more options with the same value
which in fact should be something you did not intend and in which case the plugin actually helped you spot an error in your data ;)
from vue-select.
@desislavsd thank you for the detailed explanation; you were right I had a duplicate in my data but I am still glad I asked because now It is a lot clearer to me.
I did not realise that ::
was just and empty second value and therefore providing an index.
You should definitely copy/paste this answer in your doc :)
And thank you for the great work, this component is really good; does it all in a very nice way; neat !
from vue-select.
Related Issues (14)
- displays value instead of label if set programmatically HOT 3
- field is required when working with non primitive options
- Placeholder prop HOT 1
- Question about the required attribute HOT 2
- How to handle options from a large list of remote data HOT 1
- Option is getting selected when the clear button is clicked
- Can I close the option list on clicking already selected item? HOT 2
- Have run into this issue HOT 1
- Error Cannot read property 'value' of undefined HOT 5
- Disabling select based on a boolean HOT 2
- How do I resolve broken UI ? HOT 1
- Stop selection from overflowing? HOT 1
- Options not changing when updated programmatically HOT 2
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from vue-select.