vue-select icon indicating copy to clipboard operation
vue-select copied to clipboard

v-model is not updated when getting new data via ajax

Open FerCruzBanegas opened this issue 4 years ago • 2 comments

I am using the component to get data from ajax, everything works fine until I realized that when returning via ajax one of the options with one of its different properties and selecting it does not update its status, for example:

"options": [ { "id": 21, "name": "phone", "price": "10.00" }, ... ] previous "options": [ { "id": 21, "name": "phone", "price": "30.00" }, ... ] new

I use filters (external to the component) to receive different prices on each object, so these are different, but when selecting the value of the new arrangement, the data model is still seen as:

"selected": { "id": 21, "name": "vamke-Johnseye", "price": "10.00" }

so is this an expected behavior, or is it an internal component problem?

FerCruzBanegas avatar May 03 '20 03:05 FerCruzBanegas

As I understand the flaw of this component that it is initialize the state only once, neither options or v-model represent reactive nature of the component. I have not found a way of applying new data with ajax without @search which is totally wrong way for me :(

daxsis avatar Sep 03 '20 14:09 daxsis

Try to hang watch on options

watch(options, () => {
    if( props.selected){
        selected.value = options.value.find((option) => option.id === props.selected.id);
    }
});

"version": "4.0.0-beta.6"

ramir1 avatar Jun 29 '23 04:06 ramir1