目录

Event Response via the hjs Function

When the hjs function is used to process an event, it accepts two parameters. The first parameter is the event object, which has the basic attributes in the printed event structure and also has the instance attribute. The second parameter is ownerInstance, which is a ComponentDescriptor object, similar to event.instance.

The sample code snippet is as follows:

Bind the hjs function in the HXML file.

<hjs src="./test.hjs" module="test"/>
<button bindtap="{{ test.handleTap }}">button</button>

The bound hjs function must be enclosed in two pairs of curly braces.

Implement the handleTap function in the test.hjs file. For details about how to view the print result, see Debugging and Running ASCF Source Code.

var handleTap = function(event, ownerInstance) {
  console.info('tap button', event);
};
module.exports = {
  handleTap: handleTap
};

The ComponentDescriptor object has some methods that can be used to set the component style. For details, see hjs Response Event.