erhanfirat / combo-tree

ComboTree is a jQuery Plugin which is a combobox item with tree structured data list and multi/single selection options and more.
MIT License
79 stars 67 forks source link

How to get the selected value? #44

Open kabirvs opened 2 years ago

kabirvs commented 2 years ago

How can I get the selected value?

I have tried some way:

    var comboTree1;
    jQuery(document).ready(function($) {
        comboTree1 = $('#justAnInputBox').comboTree({
            source : SampleJSONData,
            isMultiple: true,
            cascadeSelect: true,
            collapse: true,
            selectableLastNode: true,
            selected: selectedItem
        });
        var selectedTitles = comboTree1.getSelectedItemsTitle();
        console.log('selectedTitles: ' , selectedTitles);
        var selectedIds = comboTree1.getSelectedItemsId();
        console.log('selectedIds: ' , selectedIds);
    });

    Getting error as:
    jQuery.Deferred exception: comboTree1.getSelectedItemsTitle is not a function TypeError: comboTree1.getSelectedItemsTitle is not a function

Is there any way to get the selected value/ids ?

kabirvs commented 2 years ago

Also tried this according to docs. But getting similar errors:

comboTree1 = $('#justAnInputBox').comboTree({ source : SampleJSONData, isMultiple: true, cascadeSelect: true, selected: ['0'] });

// Array, One title/id, or False value return var selectedTitles = comboTree1.getSelectedItemsTitle(); var selectedIds = comboTree1.getSelectedItemsId();

// To remove plugin comboTree1.destroy();

featherit88 commented 2 years ago

This is how I did and it worked (Using the sample): comboTree2 = $('#justAnotherInputBox').comboTree({ source: SampleJSONData, isMultiple: false, }); comboTree2.onChange(function() { alert("Yeaaahhh maaannn"); let selectedIds = this.getSelectedIds(); console.log(selectedIds); });

You will receive an array.

Happy Coding!

mapsedge commented 2 years ago

THANK YOU. Docs are definitely lacking on this part.

StructuralCitizen commented 2 weeks ago

Thank you for explaining this. It could not work it out by myself from the documentation. I was trying to do

comboTree2.onChange(function() { updatecontent( alert("Yeaaahhh maaannn"); ) });

which was not working as desired.