它由架構在元件初始化之前呼叫。 根據資訊清單中定義的命名法,針對物件類型的任何輸出屬性,傳回物件結構描述。
適用於
模型導向應用程式、畫布應用程式和入口網站。
語法
getOutputSchema(context)
備註
輸出將包含資訊清單中定義的物件類型之每個屬性的 JSON 結構描述。
例如,如果資訊清單具有名為 MyOutputObject的 object 類型的輸出屬性,而您的控制項應該針對屬性的 MyOutputObject 值傳回類似以下的物件:
{
"ProductName": "sample name",
"Value": 123.4
}
然後你應該返回:
{
"MyOutputObject": {
"$schema": "http://json-schema.org/draft-04/schema#",
"type": "object",
"properties": {
"ProductName": {
"type": "string"
},
"Value": {
"type": "number"
}
}
}
}
傳回結構描述是 JSON 結構描述的子集。 JSON 結構描述支援的類型和關鍵字:
stringintegernumberarrayitems
objectproperties
boolean
參數
| 參數名稱 | 類型 | 為必填項目 | Description |
|---|---|---|---|
| 內容 | 內容 | yes | 包含參數、元件中繼資料和介面函式的 輸入屬性 。 |
Example
Control 具有呼叫的 MyOutputObject 物件類型輸出屬性,值如下所示:
{
id: 10,
productDetails: {
name: "Test Product",
price: 100.23,
},
itemList: [
{
itemId: 1,
name: "Item-1",
value: 123,
active: true,
},
{
itemId: 2,
name: "Item-2",
value: 234,
active: false,
}
]
};
GetOutputSchema 實作:
public async getOutputSchema(context: ComponentFramework.Context<IInputs>):
Promise<Record<string, unknown>> {
return Promise.resolve({
MyOutputObject: {
"$schema": "http://json-schema.org/draft-04/schema#",
"type": "object",
"properties": {
"id": {
"type": "integer"
},
"productDetails": {
"type": "object",
"properties": {
"name": {
"type": "string"
},
"price": {
"type": "number"
}
}
},
"itemList": {
"type": "array",
"items":
{
"type": "object",
"properties": {
"itemId": {
"type": "integer"
},
"name": {
"type": "string"
},
"value": {
"type": "integer"
},
"active": {
"type": "boolean"
},
}
}
}
}
}
});
}