Skip to main content
2 of 3
added 31 characters in body
Mohith Shrivastava
  • 91.9k
  • 19
  • 161
  • 214

For value attribute store values in JSON String format Like { label: 'New', value: '{"label" : "New", "value":"1"}' }

In handleChange Method convert JSON String to object and access label and value properties of that object.

Code Snippet.

basic.html

<template>
    <lightning-combobox
            name="progress"
            value={value}
            placeholder="Select"
            options={options}
            onchange={handleChange} ></lightning-combobox>

    <p>Selected value is: {value}</p>
</template>

basic.js

import { LightningElement, track } from 'lwc';

export default class ComboboxBasic extends LightningElement {
    @track value = 'inProgress';

    get options() {
        return [
            { label: 'New', value: '1' },
            { label: 'In Progress', value: '2' },
            { label: 'Finished', value: '3' },
        ];
    }

    handleChange(event) {
        let v = JSON.parse(event.detail.value);
        console.log('Label - ' + v.label);
        this.value = v.value;
    }
}

Playground link - https://developer.salesforce.com/docs/component-library/tools/playground/x0iNRAPJ/1/edit

amitghadage
  • 1.4k
  • 1
  • 9
  • 16