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 selected id on changed for each combotree instance? #30

Closed mrhieuit closed 4 years ago

mrhieuit commented 4 years ago

I have multi input with class "dropdown" on page. I init comboTree for all dropdown successfull with this code:

$(".dropdown").comboTree({
        source: productStoreFullJson,
        isMultiple: false,
        onChange: function () {
            console.log($(this).getSelectedIds());
        }
});

I want add a event onChange for get selected id when each dropdown change it's selected value. I use bellow codes:

$(".dropdown").comboTree({
        source: productStoreFullJson,
        isMultiple: false,
        onChange: function () {
            console.log($(this).getSelectedIds());
        }
});

However onChange event not work, please help me correct this. Thanks!

erhanfirat commented 4 years ago

Hi @mrhieuit,

onChange usage is below:

$(".dropdown")
.comboTree({
        source: productStoreFullJson,
        isMultiple: false
})
.onChange(function () {
            console.log($(this).getSelectedIds());
        });
mrhieuit commented 4 years ago

onChangeError

Thanks for your reply, however it's not work.

        jQuery(document).ready(function ($) {

            comboTree1 = $('#justAnInputBox').comboTree({
                source: SampleJSONData,
                isMultiple: true,
                cascadeSelect: false,
                collapse: true
            });

            comboTree3 = $('#justAnInputBox1').comboTree({
                source: SampleJSONData,
                isMultiple: true,
                cascadeSelect: true,
                collapse: false
            });

            comboTree3.setSource(SampleJSONData2);

            comboTree2 = $('#justAnotherInputBox')
                .comboTree({
                    source: SampleJSONData,
                    isMultiple: false
                })
                .onChange(function () {
                    console.log($(this).getSelectedIds());
                });
        });