简体   繁体   中英

How to bind to selected text using knockout in Select2 ajax

I'm using knockout + select2 and data for one of my dropdowns is lazyily loaded using ajax (select2 supports that).

I need to be able to bind selected text of the dropdown, but can't find a way to do it.

Does anyone know if it's possible at all?

I've had success doing this using the knockoutjs event binding:

HTML:

 select2: { minimumInputLength: 3, allowClear: true, query: ajaxQuery }, event: { change: eventHandler }" />

JS:

self.eventHandler = function (data, event) {

    };

in the event object will be a property called added or removed depending on the change that occurred. You can then use this value to update your viewmodel.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM