Combo
  • Combo.js
  • Guide
    • Concepts
      • Lifecycle Methods
  • APIs
    • Component
      • canMount
      • canUnmount
      • canUpdate
      • created
      • el
      • isMounted
      • mount
      • mounting
      • mounted
      • on
      • props
      • receiving
      • received
      • refresh
      • render
      • rendered
      • state
      • unmount
      • unmounting
      • unmounted
      • update
      • updated
      • updating
  • FAQs
    • Props
    • State
    • Events
    • Ajax
Powered by GitBook
On this page
  • Parameters
  • Example
  1. APIs
  2. Component

on

Add an event listener to one or more child components.

Parameters

  • string : selector The selector.

  • string: event The event.

  • function : cb The callback function.

Example

import { Component } from "combo-js";

const Example = new class extends Component {
	created() {
		this.data = {
			field1: "",
			field2: "",
			field3: ""
		}
	}
	rendered() {
		this.on("[type='text']", "change", (e) => {
			this.update({
				[e.target.name]: e.target.value
			});
		});
	}
	render() {
		return `
			<input name="field1" type="text" value="${this.data.field1}">
			<input name="field2" type="text" value="${this.data.field2}">
			<input name="field3" type="text" value="${this.data.field3}">

			<p>${JSON.stringify(this.data)}</p>
		`;
	}
}();

Example.mount(document.getElementById("root"));
<div id="root"></div>
PreviousmountedNextprops

Last updated 6 years ago