呼叫事件的關聯訂閱者。
備註
如果您已使用 addHandler 方法建立自訂事件,則可以在此方法中將事件名稱作為參數傳遞,以引發這些事件。
語法
Microsoft.CIFramework.raiseEvent(eventName, eventInputParameters, correlationId);
參數
| 名稱 | 類型 | 為必填項目 | Description |
|---|---|---|---|
| 事件名稱 | 繩子 | Yes | 需要叫用其處理常式的事件名稱。 |
| eventInput參數 | JSON 字串 | Yes | 需要傳遞給處理常式函數的輸入參數。 |
| correlationId | GUID | 否 | 用於將所有相關的 API 呼叫分組在一起,以進行診斷遙測。 |
返回值
Promise 的值為布林值。
Example
// Let there be an event registered to a subscriber.
handlerFunction = function(eventInput)
{
console.log(eventInput);
if(eventInput != null && eventInput != undefined && eventInput.size > 0)
{
inputData = eventInput.get("value");
correlationId = eventInput.get("correlationId");
console.log(inputData + " " + correlationId);
}
return Promise.resolve();
}
Microsoft.CIFramework.addHandler("oncustomevent", handlerFunction);
//Use raiseEvent API to invoke the subscribed handler of the event.
Microsoft.CIFramework.raiseEvent("oncustomevent", "test input value");
//In the main UCI page
Microsoft.CIFramework.addHandler("widgetEvent", handlerFunction);
///In the widget code
Microsoft.CIFramework.raiseEvent("widgetEvent", eventInput);
//In the widget code
Microsoft.CIFramework.addHandler("mainPageEvent", handlerFunction);
//In the main UCI page
Microsoft.CIFramework.raiseEvent("mainPageEvent", eventInput);