English
npcRun(hook, params, opt)
About 227 wordsLess than 1 minute
2025-11-24
Executes hook logic with the latest context. This is similar to how various hooks are triggered by default at the underlying level, and is suitable for implementing logic that needs to run outside the plugin lifecycle, such as button click events.
- It works the same as bizApi.npcRun.
Parameters
| Parameter | Description | Type |
|---|---|---|
| hook | Required, a hook function or hook event name | Function|String |
| params | Custom hook event parameters, passed to event receivers | Object |
| opt | Optional configuration parameter | Number |
Return Value
None
Code Example
Click a button in a field component to update the current object field value and trigger calculation and UI events.
methods:{
_onBtnClick(){
let {context, field, objApiName, dataIndex}=this.data;
let random = Math.round(Math.random()*1000)+'';
context.npcRun(p=>{
let updateData = {
[field.api_name]:random
}
// Update the current object field value
p.dataUpdater.update(objApiName, dataIndex, updateData);
return p.bizApi.triggerCalAndUIEvent({
objApiName,// Object currently initiating the calculation, required
modifiedDataIndexs:[dataIndex], // Newly added detail dataIndex. Pass it if the calculation is triggered because detail data was added
changeFields:[field.api_name], // Which fields were modified, required
triggerUiFields:[field.api_name], // Field that triggers the UI event
})
})
}
}Notes
- Try not to call this in lifecycle functions related to component loading or rendering, such as
attachedandready, as it may lead to concurrent operations and cause data inconsistency issues.
