I have the following knock out js template:
<select id="ddlExpertise" data-bind="options: expertiseList(), optionsCaption: 'All', value: expertiseField" ></select>
Is there a way to add ‘event: { change: doFilter }’ to the template from the JavaScript / knockout library?
I don’t want to put it in the template itself initially.
If I understand you correctly you want to react to change in the select and call a
doFiltermethod. The proper KO “way” to achieve this would be to subscribe to changes on theexpertiseFieldlike so:Every time someone selects a new value on the select KO will update the expertiseField and your subscribe function will be called. It receives the new value allowing you to filter something or whatever. KO internally uses the change event to do the two-way data binding.
Hope this helps.