Custom Action
API Definition
const action = Tingyun.newAction(options);
Parameters
- options: Action configuration object.
name: Action name. String type. Required.context: Additional data included in the action. Object type. Optional.
Return Object
Returns an action object, which can be used to end the action. The action object includes the following functions:
-
end: End the action.action.end(options);options: End action configuration object. Optional.context: Additional data included in the action. Object type. Optional.status: Set action statussuccessorfail, default issuccess. String type. Optional.
-
fail: End the action with a failure status (shorthand for end with status=fail).action.fail(options);options: End action configuration object. Optional.context: Additional data included in the action. Object type. Optional.
Example
Simulate a submit order action.
import Tingyun from '../agent/init';
Page({
data: {
order: {}
},
// Submit order callback
submitOrder() {
// Create submit order action
const action = Tingyun.newAction({
name: 'Submit Order',
context: {
orderId: this.order.id
}
});
wx.request({
url: SUBMIT_ORDER_URL,
success() {
// Action success
action.end();
},
fail(res) {
// Action failure
action.fail({
context: {
errMsg: res.errMsg
}
});
}
})
}
})